【问题标题】:after upgrade to gradle 4.x - unable to resolve warning for JEE project升级到 gradle 4.x 后 - 无法解决 JEE 项目的警告
【发布时间】:2017-09-27 17:47:59
【问题描述】:

我无法摆脱 gradle 4.2 版本中的警告:

Gradle now uses separate output directories for each JVM language, but this build assumes a single directory for all classes from a source set. This behaviour has been deprecated and is scheduled to be removed in Gradle 5.0
    at build_d02ctf5wwx94ec3duxv44z2cn$_run_closure3$_closure6.doCall(...\build.gradle:56)

项目构建 EJB jar,因此 beans.xml 文件必须在类输出文件夹中结束。 我发现的推荐修复方法是替换警告中提到的行:

sourceSets {
  main {
    output.resourcesDir = java.outputDir
  }
  test {
    output.resourcesDir = java.outputDir
  }
}

到:

sourceSets {
  main {
    output.resourcesDir = new File(buildDir, "classes/java/main")
  }
  test {
    output.resourcesDir = new File(buildDir, "classes/java/main")
  }
}

这解决了警告,beans.xml 是它需要的地方。我无法弄清楚的问题是构建中有另一个项目依赖于 ejb 项目并运行测试。使用第二种方法,它似乎无法识别 beans.xml 文件(测试中的焊接注入不起作用)

项目结构:

build.gradle
/ejb-project (builds ejb's and copies beans.xml)
/it-test-project (uses Services from ejb)
/st-test-project
/war-project
/ear-project

it-test-project 包含一个 project() 依赖项和这个 sourceSets:

dependencies {    
  testCompile project(':ejb-project')
  testRuntime project(':ejb-project')
}

sourceSets {
  test {
    // output.resourcesDir = new File(buildDir, "classes/java/main")
    output.resourcesDir = output.classesDir
  }
}

我不明白测试中的注入在上面的变体中是如何工作的,但是一旦我切换到注释的那个就不行了。我认为它与文件引用和依赖项有关,但我不明白这里的正确选项是什么。

任何建议都会很棒:)

【问题讨论】:

  • 您好,我也遇到了同样的问题。有任何更新吗?
  • 还没有。我接受警告。有时间我会把项目剥离出来放到github上,让更多有知识的人看看
  • 知道了,谢谢!

标签: java jakarta-ee gradle gradle-dependencies source-sets


【解决方案1】:

所以。经过一番挖掘,我可以通过做两件事来摆脱警告信息:

  1. 睁开眼睛:测试失败,因为缺少 beans.xml 文件,该文件不在 java/main 中,但在测试文件夹中。因此上面的注释行不起作用,beans.xml 不存在。因此,请确保您引用正确的文件夹实际上是我的解决方案。

  2. 将 resourcesDir 添加/更改到测试文件夹。

这个 sn-p 不会导致警告:

sourceSets {
    test {
         output.resourcesDir = new File(buildDir, "classes/java/test")
    }
}

不确定这是否是最好的方法,因为这意味着 java 源集文件夹。以某种方式正确引用它们会很好 - 但因为我知道它的“java” - 我可以接受这个解决方案。

【讨论】:

    猜你喜欢
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多