I was working with maven and aspectj plugin and was fine, recently I move to gradle, I already have the configuration to build/compile with aspects and that is working fine, but for integration tests are not working fine. I have the following configuration
sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir "src/main/resources/"
}
}
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/test/it')
}
resources.srcDir file('src/test/resources')
}
generated {
java {
srcDirs = [
"src/main/generated"
]
}
compileClasspath += sourceSets.main.output
}
}
but the aspects are not compiled/working correctly in the integration test. what I tried to do is the following configuration
compileIntegrationTestJava{
sourceCompatibility="1.7"
targetCompatibility="1.7"
dependsOn generateQueryDSL
source generateQueryDSL.destinationDir
dependsOn configurations.ajc.getTaskDependencyFromProjectDependency(true, "compileJava")
doLast{
ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath)
ant.iajc(source:"1.7", target:"1.7",
destDir:sourceSets.integrationTest.output.classesDir.absolutePath, maxmem:"512m", fork:"true",
aspectPath:configurations.aspects.asPath,
sourceRootCopyFilter:"**/.svn/*,**/*.java",classpath:configurations.compile.asPath){
sourceroots{
sourceSets.main.java.srcDirs.each{
pathelement(location:it.absolutePath)
}
sourceSets.integrationTest.java.srcDirs.each{
pathelement(location:it.absolutePath)
}
}
}
}
}
And I get this error.
[ant:iajc] [error] build config error: bad sourceroot: \src\integrationTest\java
If I change the line sourceSets.integrationTest.java.srcDirs.each
for sourceSets.test.java.srcDirs.each
, the IT under /src/test/it
are not being compiled and are not moved to the correct package, BUT if I put my IT test under /src/test/java
that compile correctly.
I would like to know how to put the correct sourceSets
to point src/test/it
and how to add to the classpath some classes instead of add
sourceroots{
sourceSets.main.java.srcDirs.each
As this makes the whole classes be added to the clasess/test/
directory
If you have any link or guide to do this, will be truly appreciate
I tackled this and got it working I believe.
When you say:
Do you mean 'why do you need to write all that code to add a
srcDir
'? I'm with you!What I believe got this working for me is:
Where I'm only weaving with Spring-aspects such as for transactions.
The tricky part was the need to add:
That was to eliminate the extra non-existant path. That is:
sourceSets.integrationTest.java.srcDirs
contains (absolute paths to):src/integrationTest/java
andsrc/integration-test/java
And before I put in this guard ajc was failing with
[ant:iajc] [error] build config error: bad sourceroot: \src\integrationTest\java
just like you. I determined this by adding this debug task (very helpful):and run
gradle printprojectDebug
.I'm still testing to see if this is working as I'm getting errors that I haven't fully determined if is from aspect weaving problems. But it should get you working again.
Hope my feedback helps (anyone!).