Skip to content

Commit 6f4e22e

Browse files
committed
Prep for 1.2.0 release
2 parents 8323232 + d04565a commit 6f4e22e

File tree

9 files changed

+91
-18
lines changed

9 files changed

+91
-18
lines changed

.travis.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,24 @@ dist: trusty
44
jdk: openjdk11
55
android:
66
components:
7-
- tools
8-
- android-29
9-
- build-tools-29.0.2
7+
- extra-android-m2repository
8+
9+
env:
10+
global:
11+
- TARGET_VERSION=30
12+
- ANDROID_BUILD_TOOLS_VERSION=30.0.2
13+
- ANDROID_HOME=~/android-sdk
14+
15+
before_install:
16+
- touch $HOME/.android/repositories.cfg
17+
- wget "https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip" -O commandlinetools.zip
18+
- unzip commandlinetools.zip -d $ANDROID_HOME/
19+
- yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager "platforms;android-${TARGET_VERSION}" --sdk_root=$ANDROID_HOME
20+
- yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" --sdk_root=$ANDROID_HOME
21+
22+
before_script:
23+
- chmod +x gradlew
24+
1025
script:
1126
- rm -Rf $HOME/.m2/repository/com/ibotta/gradle/aop/
1227
- ./publishLocal.sh

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ buildscript {
5050
5151
dependencies {
5252
...
53-
classpath "com.ibotta:plugin:1.1.0"
53+
classpath "com.ibotta:plugin:1.2.0"
5454
...
5555
}
5656
}
@@ -70,7 +70,7 @@ buildscript {
7070
7171
dependencies {
7272
...
73-
classpath("com.ibotta:plugin:1.1.0")
73+
classpath("com.ibotta:plugin:1.2.0")
7474
...
7575
}
7676
}
@@ -134,12 +134,12 @@ aopWeave {
134134

135135
# A Note on Kotlin 1.5+, SAM Conversion, Lambdas and AOP Annotations
136136
As of Kotlin 1.5.0 the compiler now performs Single Abstract Method (SAM) conversions. This, unfortunately, seems to
137-
break certain aspects of AspectJ weaving. For an example, please see issue #8.
137+
break certain aspects of AspectJ weaving. For an example, please see issue [#8](https://github.com/Ibotta/gradle-aspectj-pipeline-plugin/issues/8).
138138

139139
If you have lambdas that aren't being woven correctly by AspectJ, you can work around it by using the following
140140
compiler option:
141141

142-
```aidl
142+
```
143143
kotlinOptions {
144144
freeCompilerArgs = ["-Xsam-conversions=class"]
145145
}
@@ -148,9 +148,9 @@ kotlinOptions {
148148
# We Have Sample Apps!
149149
In this project, you will find a few sample apps that use this plugin to perform some simple AOP weaving. They include tests to help prove that the weaving occurred, and is running as expected. Maybe you have a Kotlin only project, or Java only, or a mix! We have examples of each:
150150

151-
- [Kotlin Only Sample App](sample-kotlin)
152-
- [Java Only Sample App](sample-java)
153-
- [Mixed Java/Kotlin Sample App](sample-mixed)
151+
- [Kotlin Only Sample App](sample-kotlin)
152+
- [Java Only Sample App](sample-java)
153+
- [Mixed Java/Kotlin Sample App](sample-mixed)
154154

155155
# How To Build The Project
156156
If you've made no code changes to the project, and simply want to build it, then you can just run the following command from the root of the project: `./gradlew build`

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Plugin {
88
const val DISPLAY_NAME = "Android AspectJ Gradle Plugin"
99
const val JVM_TARGET = "1.8"
1010
private const val BUILD_NUMBER = "" // Dynamically updated by publishLocal.sh on Travis. Otherwise left as-is.
11-
const val VERSION = "1.1.0$BUILD_NUMBER"
11+
const val VERSION = "1.2.0$BUILD_NUMBER"
1212
val TAGS = listOf("Gradle", "Plugin", "Android", "AspectJ", "Kotlin", "Java")
1313
}
1414

@@ -37,14 +37,14 @@ object Sdk {
3737
}
3838

3939
object Versions {
40-
const val ANDROID_BUILD_TOOLS_VERSION = "4.1.0"
40+
const val ANDROID_BUILD_TOOLS_VERSION = "7.0.2"
4141
const val APPCOMPAT_VERSION = "1.1.0"
4242
const val ASPECTJ_VERSION = "1.9.6"
4343
const val GRADLE_PLUGIN_PUBLISH_VERSION = "0.12.0"
4444
const val JACOCO_ANDROID_VERSION = "0.2"
4545
const val JUNIT_VERSION = "5.7.0"
4646
const val KOTLIN_VERSION = "1.4.10"
47-
const val KOTLIN_DSL_VERSION = "1.4.1"
47+
const val KOTLIN_DSL_VERSION = "2.1.6"
4848
const val KOTLINX_SERIALIZATION_RUNTIME_VERSION = "0.20.0"
4949
const val MOCKITO_CORE_VERSION = "3.5.13"
5050
const val MOCKK_VERSION = "1.10.2"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

plugin/src/main/kotlin/com/ibotta/gradle/aop/ExtFunctions.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.ibotta.gradle.aop
22

3+
import com.android.build.gradle.tasks.ExtractAnnotations
34
import com.hiya.plugins.JacocoAndroidUnitTestReportExtension
45
import org.gradle.api.Project
56
import org.gradle.api.Task
67
import org.gradle.api.UnknownDomainObjectException
7-
import org.gradle.api.provider.Provider
88
import org.gradle.api.tasks.TaskContainer
99
import org.gradle.api.tasks.TaskProvider
1010
import org.gradle.api.tasks.compile.AbstractCompile
@@ -15,6 +15,7 @@ private const val KAPT_TASK_TEMPLATE = "kapt%sKotlin"
1515
private const val JAVA_COMPILE_TASK_TEMPLATE = "compile%sJavaWithJavac"
1616
private const val KOTLIN_COMPILE_TASK_TEMPLATE = "compile%sKotlin"
1717
private const val JACOCO_REPORT_TASK_TEMPLATE = "jacocoTest%sUnitTestReport"
18+
private const val EXTRACT_ANNOTATIONS_TASK_TEMPLATE = "extract%sAnnotations"
1819
private const val JACOCO_ANDROID_REPORT_EXTENSION = "jacocoAndroidUnitTestReport"
1920
const val LANG_JAVA = "Java"
2021
const val LANG_KOTLIN = "Kotlin"
@@ -56,6 +57,16 @@ fun Project.jacocoReportTaskProvider(variantName: String): TaskProvider<JacocoRe
5657
}
5758
}
5859

60+
fun Project.extractAnnotationsTaskProvider(variantName: String): TaskProvider<ExtractAnnotations>? {
61+
val extractAnnotationsTask = tasks.namedOrNull(EXTRACT_ANNOTATIONS_TASK_TEMPLATE.format(variantName))
62+
63+
return if (extractAnnotationsTask != null) {
64+
extractAnnotationsTask as TaskProvider<ExtractAnnotations>
65+
} else {
66+
null
67+
}
68+
}
69+
5970
fun Project.jacocoAndroidReportExtension(): JacocoAndroidUnitTestReportExtension? {
6071
val jacocoExt = extensions.findByName(JACOCO_ANDROID_REPORT_EXTENSION)
6172

plugin/src/main/kotlin/com/ibotta/gradle/aop/PipelineAopWeaverPlugin.kt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.android.build.gradle.AppPlugin
55
import com.android.build.gradle.BaseExtension
66
import com.android.build.gradle.LibraryExtension
77
import com.android.build.gradle.LibraryPlugin
8+
import com.android.build.gradle.tasks.ExtractAnnotations
89
import com.hiya.plugins.JacocoAndroidUnitTestReportExtension
910
import org.gradle.api.GradleException
1011
import org.gradle.api.Plugin
@@ -35,6 +36,7 @@ class PipelineAopWeaverPlugin : Plugin<Project> {
3536
private const val ANDROID_JAR_TEMPLATE = "%s/platforms/%s/android.jar"
3637
private const val PRE_WEAVE_DIR_TEMPLATE = "preWeave/%s/%s"
3738
private const val POST_WEAVE_DIR_TEMPLATE = "postWeave/%s"
39+
private const val PATTERN_ORIGINAL_KOTLINC_OUTPUT_DIR = "tmp/kotlin-classes/"
3840
private const val AOP_WEAVE_TASK = "aopWeave%s"
3941
private const val AOP_LOG = "aop.log"
4042
}
@@ -90,6 +92,7 @@ class PipelineAopWeaverPlugin : Plugin<Project> {
9092
val aopWeaveProvider = project.tasks
9193
.register(AOP_WEAVE_TASK.format(variantNameCapitalized), AopWeaveTask::class.java)
9294
val jacocoReportTaskProvider = project.jacocoReportTaskProvider(variantNameCapitalized)
95+
val extractAnnotationsTaskProvider = project.extractAnnotationsTaskProvider(variantNameCapitalized)
9396

9497
// Before Kapt can run, we'll need to restore any pre-weave classes from previous
9598
// runs of compile tasks back into the destination directories. This is where Kapt
@@ -112,6 +115,13 @@ class PipelineAopWeaverPlugin : Plugin<Project> {
112115
configureJacocoReportTask(jacocoReportTaskProvider, postWeaveDir)
113116
}
114117

118+
// We may encounter an "extract<Variant>Annotations" task which expects the original
119+
// Kotlin compilation directory to exist. We'll need to reconfigure it to work
120+
// correctly.
121+
if (extractAnnotationsTaskProvider != null) {
122+
configureExtractAnnotationsTask(extractAnnotationsTaskProvider, preWeaveKotlinDir)
123+
}
124+
115125
// We'll need this jar for weaving.
116126
val androidJarPath = ANDROID_JAR_TEMPLATE.format(
117127
android.sdkDirectory.absolutePath,
@@ -219,6 +229,43 @@ class PipelineAopWeaverPlugin : Plugin<Project> {
219229
}
220230
}
221231

232+
/**
233+
* At some point in the 7.0.X versions of the Android Gradle Plugin changes, an
234+
* "extract<Variant>Annotations" started appearing to run just after Kotlin compilation. This
235+
* task started to fail, as it no longer could find the
236+
* "<project>/build/tmp/kotlin-classes/<variant>" directory.
237+
*
238+
* Since this directory was never created due to how we are managing the output directories on
239+
* compilation tasks (in order to allow AOP weaving to occur), we need to make sure two things
240+
* happen:
241+
*
242+
* 1. Make sure that "extract<Variant>Annotations" task doesn't fail due to a missing directory.
243+
* We'll simply make sure this directory exists, as a workaround.
244+
*
245+
* 2. We need to ensure the actual Kotlin compilation output directory is included in the list
246+
* needed by this task. Unfortunately, "classpath" is what we'd like to modify, but it's
247+
* immutable. However, looking at the logic in the "ExtractAnnotations" class, it copies
248+
* everything from "bootClasspath" to "classpath" before executing. And "bootClasspath" is
249+
* mutable. So if we add the true compilation output directory to the "bootClasspath", it will
250+
* pick up the compiled classes correctly, and "just work".
251+
*/
252+
private fun configureExtractAnnotationsTask(
253+
extractAnnotationsProvider: TaskProvider<ExtractAnnotations>,
254+
preWeaveKotlinDir: Provider<Directory>
255+
) {
256+
extractAnnotationsProvider.configure {
257+
doFirst {
258+
classpath.files.forEach {
259+
if (it.path.contains(PATTERN_ORIGINAL_KOTLINC_OUTPUT_DIR) && !it.exists()) {
260+
it.mkdirs()
261+
}
262+
}
263+
}
264+
265+
bootClasspath += project.files(preWeaveKotlinDir)
266+
}
267+
}
268+
222269
private fun configureAopWeaveTask(
223270
project: Project,
224271
extension: AopWeaveExtension,

sample-java/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ android {
3333
}
3434

3535
lintOptions {
36-
isWarningsAsErrors = true
36+
isWarningsAsErrors = false
3737
isAbortOnError = true
3838
}
3939

sample-kotlin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ android {
3535
}
3636

3737
lintOptions {
38-
isWarningsAsErrors = true
38+
isWarningsAsErrors = false
3939
isAbortOnError = true
4040
}
4141

sample-mixed/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ android {
3535
}
3636

3737
lintOptions {
38-
isWarningsAsErrors = true
38+
isWarningsAsErrors = false
3939
isAbortOnError = true
4040
}
4141

0 commit comments

Comments
 (0)