【问题标题】:gradle-aspectj: Weaving & ajc compiler options working in compile but not in test taskgradle-aspectj:编织和 ajc 编译器选项在编译中工作但在测试任务中不工作
【发布时间】:2015-12-26 18:58:49
【问题描述】:

我已经通过 AJDT 插件在 Eclipse 中成功设置了编织,并通过 gradle-aspectj 插件在我的 gradle 构建中成功设置了编织(这花费了相当长的时间......)。

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

但是,由于许多测试失败,gradle“测试”任务失败了。我可以将大部分故障追溯到某个方面(这里:对于 spring 事务)不起作用或某些用于编码的 ajc 编译器选项未处于活动状态(有关详细信息,请参阅here)。从 Eclipse 触发时,相同的测试运行良好。

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

我找到了一些相关的question,但这并没有解决我的问题。看起来仍然没有选择任何方面,也没有激活编译器选项(我只在测试中看到编码错误)。

我的(缩写)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 的 sn-p 解决。 从 gradle 运行时测试中不存在的方面的问题仍然存在。 大多数测试失败是因为

org.neo4j.graphdb.NotInTransactionException

表示基于方法的注解

@Transactional

无效。 有什么想法吗?

【问题讨论】:

    标签: spring gradle aspectj build.gradle ajdt


    【解决方案1】:

    我没有尝试过,但根据plugin description,我认为您应该将其添加到您的 Gradle 配置文件中:

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

    【讨论】:

    • 谢谢,这有助于解决编码问题!不过,测试中缺少方面的问题仍然存在(请参阅更新的问题)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多