Aspectj plugin does not work with gradle 1.5

The “Aspject Plugin” as it is described in “http://github.com/breskeby/gradleplugins/blob/0.9-upgrade/aspectjPlugin/aspectJ.gradle” does not work with gradle-1.5. With gradle-1.4 there is no problem.

task compileJava(dependsOn: JavaPlugin.PROCESS_RESOURCES_TASK_NAME, overwrite: true) {

dependsOn configurations.ajc.getTaskDependencyFromProjectDependency(true, “compileJava”)

doLast{

ant.taskdef( resource:“org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties”, classpath: configurations.ajc.asPath)

ant.iajc(source:sourceCompatibility, target:targetCompatibility, destDir:sourceSets.main.output.classesDir.absolutePath, maxmem:“512m”, fork:“true”,

aspectPath:configurations.aspects.asPath, inpath:configurations.ajInpath.asPath, sourceRootCopyFilter:"/.svn/*,/*.java",classpath:configurations.compile.asPath){

sourceroots{

sourceSets.main.java.srcDirs.each{

pathelement(location:it.absolutePath)

}

}

}

}

}

The task overwrite mechanism seems not working anymore.

This plugin doesn’t work with Gradle 1.6 either. There must have been an API change the broke how the AspectJ plugin was overriding the normal java compile task… Any ideas on a solution?

Has anyone an example how to use AspectJ with Gradle 1.6?

Overwriting tasks has known problems. Internal changes in 1.5 have (incidentally) made these problems visible for the ‘compileJava’ task. If you need to effectively replace a task, consider overwriting (just) its task action.

Hello, can you show us an example, how to overwrite the compileJava action?

During “configure” i do:

if (some condition) {

task compileJava(type:CompileAspectTask, dependsOn: [subModules.jar, ‘processResources’], overwrite: true)

}

But it never runs the CompileAspectTask and does normal compileJava.

Even if I write: task compileJava(overwrite:true) << {

println(“compiling aspects”) }

the sentence is never written :frowning:

Thanks Peter, I solved my problem like this:

configure(modules) {
  compileJava {
    actions = [];
    def subModules = prj.configurations.compile.getDependencies().withType(ProjectDependency.class).collect {
                                it.dependencyProject
                            }
                  doFirst {
                    print("Compiling aspects...")
                      inputs.files project.sourceSets.main.java.srcDirs
                    outputs.files project.sourceSets.main.output.classesDir
                      ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties",
                            classpath: project.rootProject.configurations.aspectj.asPath)
                      ant.iajc(
                            source: project.sourceCompatibility,
                            target: project.targetCompatibility,
                            destDir: project.sourceSets.main.output.classesDir.absolutePath,
                            maxmem: "512m",
                            fork: "false",
                            encoding: project.rootProject.compilationEncoding,
                            debug: project.rootProject.compilationDebug,
                            debugLevel: project.rootProject.compilationDebugLevel,
                            aspectPath: project.rootProject.configurations.aspects.asPath,
                            sourceRootCopyFilter: "**/.svn/*,**/*.java",
                            classpath: project.configurations.compile.asPath,
                            excludes: "**/run_time/**/*"
                    ) {
                        srcdir { //do not use sourceroot definition, because of excludes
                            project.sourceSets.main.java.srcDirs.each {
                                pathelement(location: it.absolutePath)
                            }
                          }
                    }
                      ///compile run_time aspects
                    project.sourceSets.main.java.srcDirs.each { dir ->
                        ant.javac(
                                source: project.sourceCompatibility,
                                target: project.targetCompatibility,
                                srcDir: dir,
                                destDir: project.sourceSets.main.output.classesDir.absolutePath,
                                fork: false,
                                encoding: project.rootProject.compilationEncoding,
                                debug: project.rootProject.compilationDebug,
                                debugLevel: project.rootProject.compilationDebugLevel,
                                classpath: project.configurations.compile.asPath,
                                includes: "**/run_time/**/*.java"
                        )
                    }
                }
  }
}

Do you plan to fix this issue? Current solution seems quite dirty to me :frowning:

Fix what problem exactly?

Sorry. The problem when overwriting compileJava. We need to override this task to be able to use aspectj compiler instead of javac.

Original code: task compileJava(type:CompileAspectTask, overwrite:true)

What’s the problem with using ‘deleteActions()’ instead of ‘overwrite: true’? Why do you think it’s dirty?

The code fragment above allegedly “fixing” seems to yield the error “Could not find property ‘modules’ on root project ‘api’.” when added to my build

http://issues.gradle.org/browse/GRADLE-684 claims that there already is a plugin, and the same plugin is listed from the plugins page (the second one at the top of the page) and it evidently hasn’t worked since 1.5 according to this page. It simply does nothing when I try it, and also brings in eclipse plugin which I don’t want since I am working in IntelliJ

I suggest you at least remove the reference to it on your plugins page, so that people don’t waste time on it.

Ondrej’s code seems to contain a number of things specific to his build. I managed to remove them and was left with the following that seems to work in my build, and use the same configuration notation as the original plugin. It would be nice if this could be incorporated into a new plugin or patched back into the old one.

compileJava {

actions = [];

def subModules = configurations.compile.getDependencies().withType(ProjectDependency.class).collect {

it.dependencyProject

}

doFirst {

println(“Compiling aspects…”)

inputs.files project.sourceSets.main.java.srcDirs

outputs.files project.sourceSets.main.output.classesDir

ant.taskdef(resource: “org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties”,

classpath: project.rootProject.configurations.ajc.asPath)

ant.iajc(

source: project.sourceCompatibility,

target: project.targetCompatibility,

destDir: project.sourceSets.main.output.classesDir.absolutePath,

maxmem: “512m”,

fork: “false”,

//encoding: project.rootProject.compilationEncoding,

//debug: project.rootProject.compilationDebug,

//debugLevel: project.rootProject.compilationDebugLevel,

aspectPath: project.rootProject.configurations.aspects.asPath,

sourceRootCopyFilter: “/.svn/*,/*.java”,

classpath: project.configurations.compile.asPath,

excludes: “/run_time//*”

) {

srcdir { //do not use sourceroot definition, because of excludes

project.sourceSets.main.java.srcDirs.each {

pathelement(location: it.absolutePath)

}

}

}

///compile run_time aspects

project.sourceSets.main.java.srcDirs.each { dir ->

ant.javac(

source: project.sourceCompatibility,

target: project.targetCompatibility,

srcDir: dir,

destDir: project.sourceSets.main.output.classesDir.absolutePath,

fork: false,

//encoding: project.rootProject.compilationEncoding,

//debug: project.rootProject.compilationDebug,

//debugLevel: project.rootProject.compilationDebugLevel,

classpath: project.configurations.compile.asPath,

includes: “/run_time//*.java”

)

}

}

}

There’s still some additional stuff to cleanup however as I am getting these messages: Calling TaskInputs.files(Object…) after task execution has started has been deprecated and is scheduled to be removed in Gradle 2.0. Check the configuration of task ‘:compileJava’. Calling TaskOutputs.files(Object…) after task execution has started has been deprecated and is scheduled to be removed in Gradle 2.0. Check the configuration of task ‘:compileJava’.

I wrapped the stuff from the Spring Security project in a separate plugin, which you can easily import in your own project. Instructions here: https://github.com/eveoh/gradle-aspectj

It’s not perfect - Gradle should provide native support for AspectJ - but at least it’s something.

The ‘inputs.files’ and ‘outputs.files’ lines have to be moved outside ‘doFirst { … }’ because they are configuration, not execution.

Looks interesting since you provided a repo for it, but is it spring specific? I believe in preceding examples the goal was compile time weaving spring or no spring.

It’s not Spring specific, you should be able to use it with any Java/AJ project.

Just to let you guys know. I had the same problem with IntelliJ 13.1.3 and Gradle 2.0.???

_____________ Cut down your exam stress by using our latest Testking linux certification exam and high quality usmle step 1 and testkingmcdst demos. We provide updated questions with principiacollege pass guarantee along with www.hood.edu training.

1 Like