java - Integration test + aspectJ + gradle -


i working maven , aspectj plugin , fine, move gradle, have configuration build/compile aspects , working fine, integration tests not working fine. have 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 aspects not compiled/working correctly in integration test. tried 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 error.

[ant:iajc] [error] build config error: bad sourceroot: \src\integrationtest\java 

if change line sourcesets.integrationtest.java.srcdirs.each sourcesets.test.java.srcdirs.each, under /src/test/it not being compiled , not moved correct package, if put test under /src/test/java compile correctly.

i know how put correct sourcesets point src/test/it , how add classpath classes instead of add

sourceroots{                 sourcesets.main.java.srcdirs.each 

as makes whole classes added clasess/test/ directory

if have link or guide this, appreciate

i tackled , got working believe.

when say:

i know how put correct sourcesets point src/test/it , how add classpath classes instead of add sourceroots{...

do mean 'why need write code add srcdir'? i'm you!

what believe got working me is:

configurations {     querydslapt     integrationtestcompile.extendsfrom testcompile     integrationtestruntime.extendsfrom testruntime      ajc     aspectpath }  dependencies {     ...     compile group: 'org.aspectj', name: 'aspectjrt', version: '1.8.9'     compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.8.9'     aspectpath group: 'org.springframework', name: 'spring-aspects', version: '4.3.0.release'     ajc 'org.aspectj:aspectjtools:1.8.9' } 

where i'm weaving spring-aspects such transactions.

compileintegrationtestjava {     dependson generatequerydsl     classpath += sourcesets.main.runtimeclasspath     sourcecompatibility = "1.8"     targetcompatibility = "1.8"      dolast {         ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjtaskdefs.properties", classpath: configurations.ajc.aspath)         ant.iajc(source: "1.8", target: "1.8",                 maxmem: "512m", fork: "true",                 destdir: sourcesets.integrationtest.output.classesdir.absolutepath,                 aspectpath: configurations.aspectpath.aspath,                 classpath: classpath.aspath) {             sourceroots {                 sourcesets.integrationtest.java.srcdirs.each { sd ->                     if (file(sd).exists()) {                         pathelement(location: sd.absolutepath)                     }                 }             }         }     } 

the tricky part need add:

                    if (file(sd).exists()) { 

that eliminate non-existant path. is:

sourcesets.integrationtest.java.srcdirs contains (absolute paths to):

  • src/integrationtest/java ,
  • src/integration-test/java

and before put in guard ajc failing [ant:iajc] [error] build config error: bad sourceroot: \src\integrationtest\java you. determined adding debug task (very helpful):

task printprojectdebug {     dolast {         sourcesets.integrationtest.java.srcdirs.each { println }         println '---- configurations.integrationtestcompile.aspath: '         println configurations.integrationtestcompile.aspath         println '---- configurations.aspectpath.aspath:'         println configurations.aspectpath.aspath         println 'end'     } } 

and run gradle printprojectdebug.

i'm still testing see if working i'm getting errors haven't determined if aspect weaving problems. should working again.

hope feedback helps (anyone!).


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -