集成测试+ aspectJ + gradle [英] Integration test + aspectJ + gradle
问题描述
我正在使用maven和aspectj插件,并且很好,最近我转向gradle,我已经拥有可以用方面编译/编译的配置,并且工作正常,但是对于集成测试工作不正常。
我有以下配置:
sourceSets {
main {
java {
srcDir'src / main / java'
}
资源{
srcDirsrc / main / resources /
}
}
integrationTest {
java {
compileClasspath + = main.output + test.output
runtimeClasspath + = main.output + test.output
srcDir file('src / test / it ')
}
resources.srcDir文件('src / test / resources')
}
生成{
java {
srcDirs = [
src / main / generated
]
}
compileClasspath + = sourceSets.main.output
}
}
但这些方面在集成测试中没有编译/正常工作。我试图做的是以下配置:
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(位置:it.abso lutePath)
}
sourceSets.integrationTest.java.srcDirs.each {
pathelement(location:it.absolutePath)
}
}
}
}
}
我得到这个错误。 b
[ant:iajc] [error] build config error:bad sourceroot:\src\integrationTest\java
如果我将 sourceSets.integrationTest.java.srcDirs.each
更改为 sourceSets.test.java.srcDirs.each
,在 / src / test / it
下的IT没有被编译,也没有移动到正确的包,但如果我把我的IT测试在 / src / test / java
编译正确。
我想知道如何将正确的 sourceSets
指向 src / test / it
以及如何添加给类路径一些类而不是添加
sourceroots {
sourceSets.main.java.srcDirs.each
因为这会将整个类添加到 clasess / test /
目录
如果您有任何链接或指南可以做到这一点,
我解决了这个问题并且让它工作我相信。
我想知道如何将正确的sourceSets指向
src / test / it以及如何添加到类路径一些类而不是
addsourceroots {...
你的意思是'你为什么需要编写所有的代码来添加 srcDir
'?我和你在一起!
我相信这对我有效:
$ b $
配置{
querydslapt
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
ajc
aspectpath
}
依赖关系{
...
编译组:'org.aspectj',名称:'aspectjrt',版本:'1.8.9'
编译组:'org。 aspectj',name:'aspectjweaver',版本:'1.8.9'
aspectpath组:'org.springframework',名称:'spring-aspects',版本:'4.3.0.RELEASE'
ajc'org.aspectj:aspectjtools:1.8.9'
}
哪里
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)
}
}
}
}
$ / code>
棘手的部分是需要添加:
if(file(sd).exists()){
这是为了消除额外的不存在的路径。即:
$ b
sourceSets.integrationTest.java.srcDirs
包含(绝对路径):
$ b
-
src / integrationTest / java
和 -
b
$ b在我加入这名后卫之前,ajc失败了与
[ant:iajc] [error] build config error:bad sourceroot:\src\integrationTest\java
就像你一样。我通过添加这个调试任务(非常有用)确定了这一点:任务printprojectDebug {
doLast {
sourceSets.integrationTest.java.srcDirs.each {println it}
println'---- configurations.integrationTestCompile.asPath:'
println configurations.integrationTestCompile.asPath
println'---- configurations.aspectpath.asPath:'
println configurations.aspectpath.asPath
println'end'
}
}
并运行
gradle printprojectDebug
。
我仍然测试,看看这是否工作,因为我得到的错误,我还没有完全确定,如果是从方面编织问题。但它应该让你再次工作。
希望我的反馈可以帮助(任何人!)。
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
forsourceSets.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 pointsrc/test/it
and how to add to the classpath some classes instead of addsourceroots{ sourceSets.main.java.srcDirs.each
As this makes the whole classes be added to the
clasess/test/
directoryIf 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:
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{...
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:
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 only weaving with Spring-aspects such as for 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 was the need to add:
if (file(sd).exists()) {
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):task printprojectDebug { doLast { sourceSets.integrationTest.java.srcDirs.each { println it } 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 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!).
这篇关于集成测试+ aspectJ + gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!