Skip to content

Commit

Permalink
Restructure to a single project (cashapp#924)
Browse files Browse the repository at this point in the history
* Restructure to a single project
* Inform plugin whether to add runtime as project or external dependency
  • Loading branch information
jrodbx authored Jun 8, 2023
1 parent 761ce59 commit 59e545e
Show file tree
Hide file tree
Showing 457 changed files with 288 additions and 314 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Run Paparazzi Tests
run: ./gradlew -p paparazzi check

- name: Run Sample Tests
- name: Run All Tests
run: ./gradlew check

- name: Upload Test Failures
Expand Down Expand Up @@ -72,7 +69,7 @@ jobs:
java-version: 17

- name: Publish Artifacts
run: ./gradlew -p paparazzi publishMavenPublicationToMavenCentralRepository paparazzi-gradle-plugin:publishPluginMavenPublicationToMavenCentralRepository paparazzi-gradle-plugin:publishPaparazziPluginMarkerMavenPublicationToMavenCentralRepository --no-parallel
run: ./gradlew publishMavenPublicationToMavenCentralRepository paparazzi-gradle-plugin:publishPluginMavenPublicationToMavenCentralRepository paparazzi-gradle-plugin:publishPaparazziPluginMarkerMavenPublicationToMavenCentralRepository --no-parallel
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prepare_mkdocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
set -ex

# Generate the API docs
./gradlew -p paparazzi dokkaGfm
./gradlew dokkaGfm

# Dokka filenames like `-http-url/index.md` don't work well with MkDocs <title> tags.
# Assign metadata to the file's first Markdown heading.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
java-version: 17

- name: Publish Artifacts
run: ./gradlew -p paparazzi publishMavenPublicationToMavenCentralRepository paparazzi-gradle-plugin:publishPluginMavenPublicationToMavenCentralRepository paparazzi-gradle-plugin:publishPaparazziPluginMarkerMavenPublicationToMavenCentralRepository --no-parallel
run: ./gradlew publishMavenPublicationToMavenCentralRepository paparazzi-gradle-plugin:publishPluginMavenPublicationToMavenCentralRepository paparazzi-gradle-plugin:publishPaparazziPluginMarkerMavenPublicationToMavenCentralRepository --no-parallel
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
Expand Down
32 changes: 32 additions & 0 deletions build-logic/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
buildscript {
repositories {
mavenCentral()
google()
gradlePluginPortal()
}

dependencies {
classpath libs.plugin.kotlin
classpath libs.plugin.android
classpath libs.plugin.buildConfig
classpath libs.grgit
}
}

subprojects {
repositories {
mavenCentral()
google()
}

tasks.withType(JavaCompile).configureEach {
sourceCompatibility = libs.versions.javaTarget.get()
targetCompatibility = libs.versions.javaTarget.get()
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile).configureEach {
kotlinOptions {
jvmTarget = libs.versions.javaTarget.get()
}
}
}
12 changes: 12 additions & 0 deletions build-logic/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
rootProject.name = 'build-logic'

include(':paparazzi-gradle-plugin')
project(':paparazzi-gradle-plugin').projectDir = new File('../paparazzi-gradle-plugin')

dependencyResolutionManagement {
versionCatalogs {
libs {
from(files("../gradle/libs.versions.toml"))
}
}
}
58 changes: 58 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ buildscript {
dependencies {
classpath libs.plugin.kotlin
classpath libs.plugin.android
classpath libs.plugin.mavenPublish
classpath libs.plugin.dokka
classpath libs.plugin.versions
classpath libs.plugin.spotless
classpath libs.plugin.buildConfig
classpath libs.plugin.ksp
classpath libs.grgit

// Normally you would declare a version here, but we use dependency substitution in
// settings.gradle to use the version built from inside the repo.
Expand All @@ -21,6 +26,8 @@ buildscript {
}

subprojects {
version = property("VERSION_NAME") as String

repositories {
mavenCentral()
google()
Expand Down Expand Up @@ -48,6 +55,39 @@ subprojects {
}
}

plugins.withId('com.vanniktech.maven.publish') {
publishing {
repositories {
maven {
name = "projectLocalMaven"
url = "${rootProject.buildDir}/localMaven"
}
/**
* Want to push to an internal repository for testing?
* Set the following properties in ~/.gradle/gradle.properties.
*
* internalUrl=YOUR_INTERNAL_URL
* internalUsername=YOUR_USERNAME
* internalPassword=YOUR_PASSWORD
*/
maven {
name = "internal"
url = providers.gradleProperty("internalUrl")
credentials(PasswordCredentials)
}
}
}
}

tasks.register('emptySourcesJar', Jar) {
// TODO: fetch sources from the corresponding AOSP repos.
archiveClassifier = 'sources'
}

tasks.register('emptyJavadocJar', Jar) {
archiveClassifier = 'javadoc'
}

apply plugin: 'com.diffplug.spotless'
spotless {
kotlin {
Expand All @@ -70,3 +110,21 @@ subprojects {
tasks.register("clean", Delete).configure {
delete rootProject.buildDir
}

allprojects { project ->
tasks.register("mavenLocalize").configure { task ->
def projectRootDir = project.projectDir
task.doFirst {
projectRootDir.eachFileRecurse(groovy.io.FileType.FILES) { file ->
if (file.name != 'build.gradle') {
return
}
def text = file.text
file.withWriter { w ->
// Intentional concatenation to prevent self-replacement
w << text.replace("//" + "mavenLocal()", "mavenLocal()")
}
}
}
}
}
23 changes: 23 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
GROUP=app.cash.paparazzi
VERSION_NAME=1.3.1-SNAPSHOT

POM_URL=https://github.com/cashapp/paparazzi/
POM_SCM_URL=https://github.com/cashapp/paparazzi/
POM_SCM_CONNECTION=scm:git:git://github.com/cashapp/paparazzi.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://[email protected]/cashapp/paparazzi.git

POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=cashapp
POM_DEVELOPER_NAME=CashApp
POM_DEVELOPER_URL=https://github.com/cashapp/

SONATYPE_HOST=DEFAULT
RELEASE_SIGNING_ENABLED=true
SONATYPE_AUTOMATIC_RELEASE=true

org.gradle.caching=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx4g
android.useAndroidX=true

# Signals to our own plugin that we are building within the repo.
app.cash.paparazzi.internal=true
2 changes: 1 addition & 1 deletion paparazzi/libs/README.md → libs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Note that layoutlib's version tracks [Android Studio Releases][studio_releases]
```
5. Build and upload:
```
./gradlew -p paparazzi publishMavenNativeLibraryPublicationToMavenCentralRepository
./gradlew publishMavenNativeLibraryPublicationToMavenCentralRepository
```
This may take a few minutes. It clones a large repo (2.4 GiB) and then uploads a large artifact
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'java-gradle-plugin'
apply plugin: 'com.vanniktech.maven.publish'
apply plugin: 'com.github.gmazzo.buildconfig'

// This module is included in two projects:
// - In the root project where it's released as one of our artifacts
// - In build-logic project where we can use it for the test-schema and samples.
//
// We only want to publish when it's being built in the root project.
if (rootProject.name == 'paparazzi-root') {
apply plugin: 'com.vanniktech.maven.publish'
}

gradlePlugin {
plugins {
paparazzi {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,16 @@ class PaparazziPlugin : Plugin<Project> {
}

private fun Project.addTestDependency() {
configurations.getByName("testImplementation").dependencies.add(
val dependency = if (isInternal()) {
dependencies.project(mapOf("path" to ":paparazzi"))
} else {
dependencies.create("app.cash.paparazzi:paparazzi:$VERSION")
)
}
configurations.getByName("testImplementation").dependencies.add(dependency)
}

private fun Project.isInternal(): Boolean {
return properties["app.cash.paparazzi.internal"].toString() == "true"
}

private fun BaseExtension.packageName(): String = namespace ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,9 @@ class PaparazziPluginTest {

val result = gradleRunner
.withArguments("testDebug", "--stacktrace")
.forwardOutput()
.runFixture(fixtureRoot) { buildAndFail() }
.runFixture(fixtureRoot) { build() }

assertThat(result.output).contains(
"An operation is not implemented: New resource loading coming soon"
)
assertThat(result.output).contains("New resource loading coming soon")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
libs {
from(files("../../../../../gradle/libs.versions.toml"))
from(files("../../../../gradle/libs.versions.toml"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ android {

tasks.withType(Test).configureEach {
testLogging {
exceptionFormat 'FULL'
showStandardStreams true
}
}
Loading

0 comments on commit 59e545e

Please sign in to comment.