Skip to content

Commit b856e9d

Browse files
authored
Introduce TaskProvider API, Remove Symlinks, Allow Connection between Plugin & Sample (#235)
* Move location of "junitPlatform" extension to Project Don't keep it on the AGP's internal TestOptions type since that seems to cause problems with the latest iterations of that plugin. Instead, move it to the Project level and update all references to it * Migrate Jacoco task integration to new lazy Gradle API * Migrate instrumentation test integration task to new lazy TaskProvider API * Remove symlinks * Remove symlinks, Part 2 Some build logic is now duplicated across plugin and instrumentation, but it's kept to a minimum. The buildSrc & deployment logic remains in a singular place and is imported into each of the child projects on demand * Add changelog for Plugin 1.7.0.0 * Allow building Fat JARs of the plugin This is in preparation for using a local build of the plugin inside the sample modules * Allow sample module to use Fat JAR of plugin, if possible * Remove workaround for KotlinJvmOptions (not needed anymore) * Changelog * Update CI file to point to new file locations
1 parent 1b64ad0 commit b856e9d

37 files changed

Lines changed: 392 additions & 171 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defaults: &defaults
77
GRADLE_OPTS: -Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -Dorg.gradle.caching=true -Dorg.gradle.configureondemand=true -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false
88

99
cache_key: &cache_key
10-
key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "plugin/android-junit5/build.gradle.kts" }}-{{ checksum "instrumentation/runner/build.gradle.kts" }}-{{ checksum "instrumentation/sample/build.gradle.kts" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "buildSrc/src/main/kotlin/Artifacts.kt" }}-{{ checksum "buildSrc/src/main/kotlin/Dependencies.kt" }}
10+
key: jars-{{ checksum "plugin/build.gradle.kts" }}-{{ checksum "plugin/android-junit5/build.gradle.kts" }}-{{ checksum "plugin/gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "instrumentation/build.gradle.kts" }}-{{ checksum "instrumentation/runner/build.gradle.kts" }}-{{ checksum "instrumentation/sample/build.gradle.kts" }}-{{ checksum "instrumentation/gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "buildSrc/src/main/kotlin/Artifacts.kt" }}-{{ checksum "buildSrc/src/main/kotlin/Dependencies.kt" }}
1111

1212
version: 2
1313
jobs:

build.gradle.kts

Lines changed: 0 additions & 58 deletions
This file was deleted.

buildSrc/src/main/kotlin/Artifacts.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class DeployedCredentials(private val project: Project) {
9898
// * CI Server:
9999
// Stored in environment variables before launch
100100
val properties = Properties().apply {
101-
val credentialsFile = File(project.rootDir, "local.properties")
101+
val credentialsFile = File(project.rootDir.parentFile, "local.properties")
102102
if (credentialsFile.exists()) {
103103
load(credentialsFile.inputStream())
104104
}

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ object Plugins {
1212
// Maintenance & Build Environment
1313
const val versions: Lib = "com.github.ben-manes:gradle-versions-plugin:0.20.0"
1414
const val kotlin: Lib = "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
15+
const val shadow: Lib = "com.github.jengelman.gradle.plugins:shadow:6.1.0"
1516

1617
// Android Gradle Plugin
1718
val android35x: Agp = Agp("com.android.tools.build:gradle:3.5.4")

buildSrc/src/main/kotlin/Utilities.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import org.gradle.api.Action
22
import org.gradle.api.Project
3+
import org.gradle.api.artifacts.dsl.DependencyHandler
34
import org.gradle.api.artifacts.dsl.RepositoryHandler
45
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
6+
import org.gradle.api.file.FileCollection
57
import org.gradle.api.tasks.compile.AbstractCompile
8+
import java.io.File
9+
import java.time.Instant
10+
import java.time.ZoneId
11+
import java.time.format.DateTimeFormatter
612

713
/* RepositoryHandler */
814

@@ -55,3 +61,32 @@ private fun Project.setupCompileChain(sourceCompileName: String,
5561
// that the other way does not work!
5662
targetCompile.classpath += project.files(sourceCompile.destinationDir)
5763
}
64+
65+
/**
66+
* Provides a dependency object to the JUnit 5 plugin, if any can be found.
67+
* This will look in the build folder of the sibling project to try and find
68+
* a previously built "fat JAR", and return it in a format
69+
* compatible to the Gradle dependency mechanism. If no file can be found,
70+
* this method returns null instead.
71+
*/
72+
fun Project.findLocalPluginJar(): File? {
73+
val localLibsFolder = rootDir.parentFile.toPath()
74+
.resolve("plugin/android-junit5/build/libs")
75+
.toFile()
76+
77+
val localPluginJar = (localLibsFolder.listFiles() ?: emptyArray<File>())
78+
.sortedByDescending(File::lastModified)
79+
.firstOrNull { "fat" in it.name && "javadoc" !in it.name && "sources" !in it.name }
80+
81+
return localPluginJar
82+
}
83+
84+
/* File */
85+
86+
/**
87+
* Format the "last modified" timestamp of a file into a human readable string.
88+
*/
89+
fun File.lastModifiedDate(): String =
90+
Instant.ofEpochMilli(lastModified())
91+
.atZone(ZoneId.systemDefault())
92+
.format(DateTimeFormatter.ISO_DATE_TIME)

instrumentation/build.gradle.kts

Lines changed: 0 additions & 1 deletion
This file was deleted.

instrumentation/build.gradle.kts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
jcenter()
5+
jitpack()
6+
}
7+
dependencies {
8+
classpath(Plugins.kotlin)
9+
classpath(Plugins.android.dependency)
10+
classpath(Plugins.androidMavenPublish)
11+
classpath(Plugins.bintray)
12+
classpath(Plugins.androidMavenGradle)
13+
classpath(Plugins.versions)
14+
classpath(Plugins.dokkaCore)
15+
classpath(Plugins.dokkaAndroid)
16+
}
17+
}
18+
19+
subprojects {
20+
repositories {
21+
google()
22+
jcenter()
23+
sonatypeSnapshots()
24+
}
25+
26+
// Configure publishing (if the project is eligible for publication)
27+
configureDeployConfig()
28+
}
29+
30+
fun Project.configureDeployConfig() {
31+
// ------------------------------------------------------------------------------------------------
32+
// Deployment Setup
33+
//
34+
// Releases are pushed to JCenter via Bintray, while snapshots are pushed to Sonatype OSS.
35+
// This section defines the necessary tasks to push new releases and snapshots using Gradle tasks.
36+
// ------------------------------------------------------------------------------------------------
37+
val configuration = Artifacts.from(this) ?: return
38+
ext["deployConfig"] = configuration
39+
ext["deployCredentials"] = DeployedCredentials(this)
40+
}

instrumentation/buildSrc

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
jcenter()
7+
}
8+
9+
sourceSets {
10+
main {
11+
java.srcDir(file("../../buildSrc/src/main/kotlin"))
12+
}
13+
}

0 commit comments

Comments
 (0)