我已经通过AJDT插件在 Eclipse 中成功设置了编织,并通过gradle-aspectj插件在我的 gradle 构建中成功设置了编织(这花了相当长的时间......)。
在 Eclipse 中,这适用于生产和测试代码,即所有测试都通过。当我运行 gradle 构建时,生成的应用程序也可以正常工作,我可以看到各个方面都按预期工作。
然而,由于许多测试失败,gradle“测试”任务失败。我可以将大部分故障追溯到某个方面(这里:对于 spring 事务)不起作用或用于编码的某些 ajc 编译器选项未激活(有关详细信息,请参见此处)。当从 Eclipse 触发时,相同的测试运行良好。
为了使编织也可以用于测试,是否需要一些额外的配置?
我发现了一些相关的问题,但这并没有为我解决问题。看起来仍然没有选择任何方面,也没有激活编译器选项(我只在测试中看到编码错误)。
我的(缩写)build.gradle(注意:我很难让编织工作,所以这可能包含一些不必要的配置):
buildscript
{
dependencies
{
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE")
classpath("nl.eveoh:gradle-aspectj:1.6")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'aspectj'
configurations {
runtime
testCompile {
extendsFrom testAspectpath
}
aspectpath
testAspectpath
ajInpath
compile {
extendsFrom aspectpath
}
}
dependencies
{
// Non aspect dependencies
// ...
// Dependencies that require weaving - works for compile but not for test task
aspectpath("org.springframework:spring-context:4.2.1.RELEASE")
compile("org.springframework:spring-context:4.2.1.RELEASE")
aspectpath("org.springframework:spring-context-support:4.2.1.RELEASE")
compile("org.springframework:spring-context-support:4.2.1.RELEASE")
compile 'com.vaadin:vaadin-spring-boot-starter:1.0.0'
testCompile("org.springframework.boot:spring-boot-starter-test:${springVersion}")
// Spring Data Neo4j
compile "org.springframework.data:spring-data-neo4j:${springDataGraphVersion}"
// Additional aspects - also need to be configured in ADJT
aspectpath "org.aspectj:aspectjtools:${aspectjVersion}"
compile "org.aspectj:aspectjrt:${aspectjVersion}"
testCompile "org.aspectj:aspectjrt:${aspectjVersion}"
compile "org.springframework:spring-aspects:4.2.1.RELEASE"
aspectpath "org.springframework:spring-aspects:4.2.1.RELEASE"
compile "org.springframework:spring-instrument:3.2.1.RELEASE"
aspectpath "org.springframework:spring-instrument:3.2.1.RELEASE"
compile "org.springframework.data:spring-data-neo4j-aspects:${springDataGraphVersion}"
aspectpath "org.springframework.data:spring-data-neo4j-aspects:${springDataGraphVersion}"
// Required by spring aspects
compile "org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final"
aspectpath "org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final"
compile "javax.persistence:persistence-api:1.0"
aspectpath "javax.persistence:persistence-api:1.0"
testAspectpath sourceSets.main.output // from related question [4]
}
compileAspect {
// Works in compile but not in test task!
additionalAjcArgs = ['encoding' : 'UTF-8']
}
编辑:编码问题已通过 kriegaex 的片段解决。从 gradle 运行时测试中不存在的方面的问题仍然存在。大多数测试失败是因为
org.neo4j.graphdb.NotInTransactionException
这表明基于方法的注释
@Transactional
无效。有什么想法吗?