Skip to content

Commit f1a0b2d

Browse files
committed
Add Convention Plugins for Android
1 parent 6753f7c commit f1a0b2d

23 files changed

+180
-143
lines changed

.github/workflows/build.yaml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,5 @@ jobs:
2323
with:
2424
cache-read-only: false
2525
- run: "./gradlew qualityCheck"
26-
- run: "./gradlew test"
27-
- run: "./gradlew testEndToEnd"
28-
- run: "./gradlew testEndToEndSlow"
2926
- run: "./gradlew check"
30-
- run: "./gradlew cyclonedxBom --no-configuration-cache"
3127
# - run: "./gradlew publish"
32-
if: ${{ !contains(github.ref_name, '/') }}
33-
- uses: actions/upload-artifact@v4
34-
if: always()
35-
with:
36-
name: reports
37-
path: gradle/aggregation/build/reports
38-
# - uses: DependencyTrack/gh-upload-sbom@v3
39-
# if: ${{ !contains(github.ref_name, '/') }}
40-
# with:
41-
# apiKey: ${{ secrets.DEPENDENCYTRACK_APIKEY }}
42-
# bomFilename: "gradle/aggregation/build/reports/sbom/bom.xml"
43-
# serverHostname: ${{ secrets.DEPENDENCYTRACK_URL }}
44-
# projectName: "gradle-project-setup-howto"
45-
# projectVersion: ${{ github.ref_name }}
46-
# autoCreate: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.idea
33
build
44
target
5+
local.properties

app/build.gradle.kts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
plugins { id("org.example.gradle.component.application") }
22

3-
application { mainClass = "org.example.product.app.Application" }
4-
53
dependencies {
64
implementation(projects.bespin)
75
implementation(projects.corellia)
86
implementation(projects.kamino)
97
implementation(projects.kashyyyk)
108
implementation(projects.naboo)
119
implementation(projects.tatooine)
10+
implementation(libs.android.material)
11+
implementation(libs.androidx.appcompat)
1212
implementation(libs.guice)
1313
implementation(libs.guice.servlet)
1414
implementation(libs.slf4j.api)
1515
runtimeOnly(libs.slf4j.simple)
16-
providedCompile(libs.jakarta.servlet.api)
1716

18-
mockApiImplementation(projects.app)
19-
mockApiImplementation(libs.guava)
17+
androidTestImplementation(libs.androidx.test.junit)
18+
androidTestImplementation(libs.androidx.test.monitor)
19+
androidTestImplementation(libs.junit4)
2020

2121
testImplementation(libs.junit.jupiter.api)
22-
23-
testEndToEndImplementation(projects.app) { capabilities { requireFeature("mock-api") } }
24-
testEndToEndImplementation(libs.guava)
25-
testEndToEndImplementation(libs.junit.jupiter.api)
2622
}

gradle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Configure the Grade Daemon - memory and same encoding on all machines
2-
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=384m -XX:+HeapDumpOnOutOfMemoryError
2+
org.gradle.jvmargs=-Xmx6g -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=384m -XX:+HeapDumpOnOutOfMemoryError
33

44
# activate Gradle configuration cache - instantly start builds that ran before, full parallelism
55
org.gradle.configuration-cache=true
@@ -8,3 +8,5 @@ org.gradle.configuration-cache=true
88

99
# activate Gradle build cache - switch between branches/commits without rebuilding every time
1010
org.gradle.caching=true
11+
12+
android.useAndroidX=true

gradle/aggregation/build.gradle.kts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
1+
import com.android.build.api.attributes.BuildTypeAttr
2+
13
plugins {
24
id("org.gradle.java")
35
id("org.example.gradle.base.lifecycle")
46
id("org.example.gradle.base.dependency-rules")
57
id("org.example.gradle.check.format-gradle")
6-
id("org.example.gradle.report.code-coverage")
8+
// id("org.example.gradle.report.code-coverage")
79
id("org.example.gradle.report.plugin-analysis")
810
id("org.example.gradle.report.sbom")
9-
id("org.example.gradle.report.test")
11+
// id("org.example.gradle.report.test")
1012
}
1113

1214
dependencies { implementation(projects.app) }
15+
16+
configurations {
17+
compileClasspath { selectRelease() }
18+
runtimeClasspath { selectRelease() }
19+
testCompileClasspath { selectRelease() }
20+
testRuntimeClasspath { selectRelease() }
21+
}
22+
23+
fun Configuration.selectRelease() {
24+
attributes.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "jar")
25+
attributes.attribute(BuildTypeAttr.ATTRIBUTE, objects.named("release"))
26+
}
27+
28+
// Allow AARs to appear along JARs on the joint classpath for reports
29+
dependencies {
30+
attributesSchema { getMatchingStrategy(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE).compatibilityRules.add(AarJarCompatibility::class.java) }
31+
attributesSchema { getMatchingStrategy(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE).compatibilityRules.add(AarJarStringCompatibility::class.java) }
32+
}
33+
34+
class AarJarCompatibility : AttributeCompatibilityRule<LibraryElements> {
35+
override fun execute(details: CompatibilityCheckDetails<LibraryElements>) {
36+
if (details.producerValue?.name == "aar") {
37+
details.compatible()
38+
}
39+
}
40+
}
41+
42+
class AarJarStringCompatibility : AttributeCompatibilityRule<String> {
43+
override fun execute(details: CompatibilityCheckDetails<String>) {
44+
if (details.producerValue == "aar" || details.producerValue == "android-classes-jar") {
45+
details.compatible()
46+
}
47+
}
48+
}

gradle/libs.versions.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
[versions]
2+
android-material = "1.12.0"
3+
androidx-appcompat = "1.7.0"
4+
androidx-test = "1.1.5"
25
assertj = "3.22.0"
6+
espresso = "3.5.1"
37
guava = "33.4.0-jre"
48
guice = "5.1.0"
59
httpcomponents = "4.5.14"
@@ -22,6 +26,11 @@ velocity = "2.4.1"
2226
zookeeper = "3.9.3"
2327

2428
[libraries]
29+
android-material = { module = "com.google.android.material:material", version.ref = "android-material" }
30+
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
31+
androidx-espresso = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso"}
32+
androidx-test-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-test" }
33+
androidx-test-monitor = { module = "androidx.test:monitor" }
2534
assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj" }
2635
commons-io = { module = "commons-io:commons-io" }
2736
guava = { module = "com.google.guava:guava", version.ref = "guava" }
@@ -39,6 +48,7 @@ jakarta-mail-impl = { module = "com.sun.mail:jakarta.mail", version.ref = "jakar
3948
jakarta-servlet-api = { module = "jakarta.servlet:jakarta.servlet-api", version.ref = "jakarta-servlet" }
4049
jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "jsr305" }
4150
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" }
51+
junit4 = { module = "junit:junit" }
4252
opensaml = { module = "org.opensaml:opensaml", version.ref = "opensaml" }
4353
org-json = { module = "org.json:json", version.ref = "org-json" }
4454
org-reflections = { module = "org.reflections:reflections", version.ref = "org-reflections" }

gradle/plugins/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
plugins { `kotlin-dsl` }
22

3-
repositories { gradlePluginPortal() }
3+
repositories {
4+
gradlePluginPortal()
5+
google()
6+
}
47

58
dependencies {
9+
implementation("com.android.tools.build:gradle:8.3.0")
610
implementation("com.autonomousapps:dependency-analysis-gradle-plugin:2.19.0")
711
implementation("com.diffplug.spotless:spotless-plugin-gradle:7.2.1")
812
implementation("com.gradle:develocity-gradle-plugin:4.1")

gradle/plugins/src/main/kotlin/org.example.gradle.base.dependency-rules.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ jvmDependencyConflicts {
1414
logging { enforceSlf4JSimple() }
1515

1616
patch {
17+
// Avoid conflict between 'javax.activation' and 'jakarta.activation-api' in the
18+
// detachedConfiguration that is input to AndroidLintTask.lintTool.classpath
19+
// Because for 'detachedConfigurations' you cannot inject conflict resolution strategies
20+
// select(JAVAX_ACTIVATION_API, "jakarta.activation:jakarta.activation-api")
21+
// would not solve the issue.
22+
module("com.android.tools:repository") {
23+
removeDependency("com.sun.activation:javax.activation")
24+
addApiDependency("jakarta.activation:jakarta.activation-api")
25+
}
26+
1727
module("com.github.racc:typesafeconfig-guice") {
1828
// remove and re-add due to 'no_aop' classifier
1929
removeDependency("com.google.inject:guice")

gradle/plugins/src/main/kotlin/org.example.gradle.base.identity.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins { id("org.gradle.base") }
22

33
// Set the group required to refer to a Module "from outside".
44
// I.e., when it is published or used in Included Builds.
5-
group = "org.example.product.java"
5+
group = "org.example.product.android"
66

77
// Set the version from 'version.txt'
88
version = providers.fileContents(isolated.rootProject.projectDirectory.file("gradle/version.txt")).asText.getOrElse("")

gradle/plugins/src/main/kotlin/org.example.gradle.check.dependencies.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import com.autonomousapps.DependencyAnalysisSubExtension
22
import com.autonomousapps.tasks.ProjectHealthTask
33

44
plugins {
5-
id("org.gradle.java")
5+
id("org.gradle.java-base")
66
id("com.autonomousapps.dependency-analysis")
77
id("io.fuchs.gradle.classpath-collision-detector")
88
id("org.example.gradle.base.lifecycle")

0 commit comments

Comments
 (0)