gradle-aspectj:编织& ajc编译器选项在编译时工作,但不在测试任务中 [英] gradle-aspectj: Weaving & ajc compiler options working in compile but not in test task

查看:535
本文介绍了gradle-aspectj:编织& ajc编译器选项在编译时工作,但不在测试任务中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Eclipse中通过 AJDT 插件成功编织,并在我的gradle build中通过< a href =https://github.com/eveoh/gradle-aspectj =nofollow noreferrer> gradle-aspectj 插件(花了相当长的一段时间......)。



在Eclipse中,这适用于生产和测试代码,即所有测试都通过。
当我运行Gradle构建时,生成的应用程序也可以正常工作,我可以看到这些方面正在按预期工作。



gradletest任务许多测试失败都会失败。我可以跟踪大部分故障返回到某些方面(这里:对于spring事务)不起作用,或者某些ajc编译器选项用于编码不被激活(参见这里了解详情)。在使用Eclipse触发时,相同的测试运行正常。



是否还需要一些额外的配置才能使编织工作以用于测试?



我发现了一些相关的问题,但是这并没有为我解决问题。它仍然看起来像没有方面被拿起,也没有编译器选项是积极的(我看到编码错误只在测试)。

我的(缩写)build.gradle(注意:我很难编织工作,所以这可能包含一些不必要的配置):

$ p $ buildscript
{
依赖关系
{
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插件:'aspectj'

配置{
运行时
testCompile {
extends测试方面路径
}
纵向路径
testAspectpath
ajInpath
compile {
extends从纵向路径
}
}

依赖性
{
/ / Non方面的依赖关系
// ...

//需要的依赖关系重新编织 - 适用于编译,但不适用于测试任务
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)
编译'com.vaadin:vaadin-spring-boot-starter:1.0.0'
testCompile(org.springframework.boot:spring-boot-starter-test:$ {springVersion} )

// Spring数据Neo4j
编译org.springframework.data:spring-data-neo4j:${springDataGraphVersion}

//其他方面 - 还需要在ADJT
aspectpath中配置org.aspectj:aspectjtools:$ {aspectjVersion}
compileorg.aspectj:aspectjrt:$ {aspectjVersion}
testCompileorg。 aspectj:aspectjrt:$ {aspectjVersion}
compileorg.springframework:spring-aspects:4.2.1.RELEASE
aspectpathorg.springframework:spring-aspects:4.2.1.RELE ASE
compileorg.springframework:spring-instrument:3.2.1.RELEASE
aspectpathorg.springframework:spring-instrument:3.2.1.RELEASE
compileorg。 springframework.data:spring-data-neo4j-aspects:${springDataGraphVersion}
aspectpathorg.springframework.data:spring-data-neo4j-aspects:${springDataGraphVersion}
//必须填写弹簧方面
编译org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final
aspectpathorg.hibernate.javax.persistence:hibernate-jpa-2.0- api:1.0.1.Final
compilejavax.persistence:persistence-api:1.0
aspectpathjavax.persistence:persistence-api:1.0
testAspectpath sourceSets.main.output //从相关问题[4]
}

compileAspect {
//在编译时工作,但不在测试任务中!
additionalAjcArgs = ['encoding':'UTF-8']
}

编辑:编码问题已经解决了来自kriegaex的片段。
从gradle运行时,测试中不存在的方面问题仍然存在。
大多数测试因为


org.neo4j.graphdb.NotInTransactionException




这表明基于方法的注释


@Transactional

无效。
有什么想法?

解决方案

我还没有尝试过,但根据

  compileTestAspect {
additionalAjcArgs = ['encoding':'UTF-8']
}


I have set up weaving successfully in Eclipse via the AJDT plugin and in my gradle build via the gradle-aspectj plugin (which took quite some time...).

In Eclipse this works both for production and test code, i.e. all tests pass. When I run the gradle build, the resulting app also works fine and I can see that aspects are working as expected.

The gradle "test" task however fails as many tests fail. I can track most of the failures back to some aspect (here: for spring transactions) not working or some ajc-compiler option for encoding not being active (see here for details). The same tests do run fine when triggered from Eclipse.

Is some additional configuration required in order to get the weaving to work for tests as well?

I found some related question, however this didn't resolve the issue for me. It still looks like neither aspects are picked up, nor compiler options are active (I see encoding errors in tests only).

My (abbreviated) build.gradle (Note: I had a hard time getting weaving to work at all so this probably contains some unnecessary configuration):

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']
}

Edit: Encoding problem has been solved with snippet from kriegaex. The problem of aspects that are not present in tests when run from gradle still remains. Most tests fail because of a

org.neo4j.graphdb.NotInTransactionException

which indicates that the method based annotation

@Transactional

is not effective. Any thoughts?

解决方案

I have not tried but according to the plugin description I think you should add this to your Gradle config file:

compileTestAspect {
  additionalAjcArgs = ['encoding' : 'UTF-8']
}

这篇关于gradle-aspectj:编织&amp; ajc编译器选项在编译时工作,但不在测试任务中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆