Gradle javaCompile.doLast not working
I come across an error, in my gradle file "javaCompile.doLast" doesn't work, this is my gradle file
import org.aspectj.bridge.IMessage
import org.aspectj.bridge.MessageHandler
import org.aspectj.tools.ajc.Main
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.aspectj:aspectjtools:1.8.5'
}
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
lintOptions {
checkReleaseBuilds true
abortOnError true
}
}
final def log = project.logger
final def variants = project.android.applicationVariants
variants.all { variant ->
println "AAAAAAAA";
JavaCompile javaCompile = variant.javaCompile
javaCompile.doLast {
println "CCCC"
String[] args = ["-showWeaveInfo",
"-1.5",
"-inpath", javaCompile.destinationDir.toString(),
"-aspectpath", javaCompile.classpath.asPath,
"-d", javaCompile.destinationDir.toString(),
"-classpath", javaCompile.classpath.asPath,
"-bootclasspath", project.android.bootClasspath.join(File.pathSeparator)]
log.debug "ajc args: " + Arrays.toString(args)
println "BBBBBBB";
println javaCompile.destinationDir.toString()
println javaCompile.classpath.asPath
MessageHandler handler = new MessageHandler(true);
new Main().run(args, handler);
for (IMessage message : handler.getMessages(null, true)) {
switch (message.getKind()) {
case IMessage.ABORT:
case IMessage.ERROR:
case IMessage.FAIL:
log.error message.message, message.thrown
break;
case IMessage.WARNING:
log.warn message.message, message.thrown
break;
case IMessage.INFO:
log.info message.message, message.thrown
break;
case IMessage.DEBUG:
log.debug message.message, message.thrown
break;
}
}
}
}
repositories {
mavenCentral()
}
When I run gradle info, I see "AAA" print twice, but "BBB" and "CCC" are not printed, I don't know what happened in the gradle file I am copying "options" from https://github.com/android10/ Android-AOPExample
============= update =======================
Sorry, this is my fault, If I run "gradle clean build" in the command line, it works and works fine when I press the start button in Intellij,
but if i didn't run the command it doesn't work if i press the run button in Intellij,
So, a new question. Differences between "command line" and "Intellij launch button"
+3
source to share
No one has answered this question yet
Check out similar questions: