Hi, I need to build a multiproject using aspectj I looked at “http://wiki.gradle.org/display/GRADLE/Plugins#Plugins-AspectJplugin” buit it seems to be not updated, so I tried to upgrade it to gradle rc1.0-rc3.
Here is my attempt:
package com.amadego.utilities.gradle
import org.gradle.api.Project
import org.gradle.api.Plugin
import org.gradle.api.plugins.JavaPlugin
class AspectJPlugin implements Plugin<Project> {
public static final String ANT_ASPECTJ_TASK_DEFINITION_NAME = "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties";
public static final String AJC_CONFIGURATION_NAME = "ajc";
public static final String ASPECT_LIBS_CONFIGURATION_NAME = "aspectLibs";
@Override
void apply(Project project) {
// println "AspectJPlugin apply called"
project.getPlugins().apply(JavaPlugin.class);
project.configurations.add(AJC_CONFIGURATION_NAME)
project.configurations.add(ASPECT_LIBS_CONFIGURATION_NAME)
project.task(JavaPlugin.COMPILE_JAVA_TASK_NAME, overwrite: true) {
dependsOn project.configurations.ajc.getTaskDependencyFromProjectDependency(true, JavaPlugin.COMPILE_JAVA_TASK_NAME)
doLast {
// println "AspectJPlugin Called. classpath="+project.configurations.compile.asPath
project.ant.taskdef(resource: ANT_ASPECTJ_TASK_DEFINITION_NAME, classpath: project.configurations.ajc.asPath)
project.ant.iajc (
debug: "on",
showWeaveInfo: "false",
classpath: project.configurations.compile.asPath,
destDir: project.sourceSets.main.output.classesDir.absolutePath,
//fork: "true", maxmem: "512m", // fork is not needed
aspectpath: project.configurations.aspectLibs.asPath,
// Similar to classpath, aspectpath contains read-only, binary aspect libraries that are woven into sources but not included in the output. aspectpath accepts jar/zip files (but, unlike classpath, not directories).
//inpath: project.configurations.ajInpath.asPath,
// Read .class files for bytecode weaving from directories or zip files (like classpath).
//sourceRootCopyFilter:"**/.svn/*,**/*.java,**/*.aj", // do not copy anything, resources must be in separate dir
source: project.sourceCompatibility,
target: project.targetCompatibility,
verbose: "false"
) {
sourceroots{
project.sourceSets.main.java.srcDirs.each {
pathelement(location:it.absolutePath)
}
}
}
}
}
}
}
The plugin works fine (more or less… ) But when I use it in a multiproject it fails to calculate dependencies, while the java plugin works fine.
This is my project tree:
main/settings.gradle main/build.gradle main/prjA/build.gradle main/prjA/src/main/java/A.java main/prjB/build.gradle main/prjB/src/main/java/B.java
settings.gradle is:
include 'prjA', 'prjB'
main/build.gradle is:
subprojects {
group = "com.amadego.utilities"
version = "2.0"
}
main/prjA/build.gradle is:
apply plugin: "aspectj"
sourceCompatibility = 1.6
dependencies {
ajc "org.aspectj:aspectjtools:1.6.6"
aspectLibs project(":prjB")
compile project(":prjB")
compile "org.aspectj:aspectjrt:1.6.6"
}
jar {
manifest {
attributes "Implementation-Title": "${rootProject.description} - ${project.description}", "Implementation-Version": version
}
}
uploadArchives {
repositories {
flatDir {
dirs USER_REPOSITORY_LIB_PATH
}
}
}
main/prjB/build.gradle is:
apply plugin: "aspectj"
sourceCompatibility = 1.6
dependencies {
ajc "org.aspectj:aspectjtools:1.6.6"
compile "org.aspectj:aspectjrt:1.6.6"
}
jar {
manifest {
attributes "Implementation-Title": "${rootProject.description} - ${project.description}", "Implementation-Version": version
}
}
uploadArchives {
repositories {
flatDir {
dirs USER_REPOSITORY_LIB_PATH
}
}
}
Now, I would expect that, if I run “gradle build” from root project, gradle would build first prjB, then prjA (according to dependecies).
Indeed, this is what happens if I apply the java plugin, but, when I apply the aspectj.plugin, gradle builds projects in alphabetical order, as if was ignoring the interproject dependencies.
I guess there is something wrong in my aspectj pluginn, but I’m unable to spot it.
Can you help me? Thanks, Luca