【问题标题】:How does the Gradle compileTestJava step work?Gradle compileTestJava 步骤如何工作?
【发布时间】:2020-11-17 12:35:03
【问题描述】:

我有一个复杂的构建,其中 Java 源文件必须在编译之前进行预处理。这有点乱,但一切正常。接下来我想让junit测试工作。我在src/test/java 中添加了它们,但它们没有编译。 compileTestJava 任务为项目中的类报告数百个未找到包/类错误。

我的第一个想法是编译的类不在类路径中,因为输出目录很奇怪(参见前面关于预处理的评论),所以我明确添加了它们:

  testImplementation (
    'junit:junit:4.12',
    'org.junit.jupiter:junit-jupiter-api:5.4.2',
    fileTree(dir: "${buildDir}/classes/hej")
  )

如果我自己进行扩展 testCompileClasspath 的配置:

configurations {
  normtest.extendsFrom(testCompileClasspath)
}

并打印出类路径:

task helloWorld() {
  doLast {
    configurations.normtest.each {
      println it
    }
  }
}

类路径清楚地包括compileTestJava 报告为缺失的类。

我忽略了什么?

【问题讨论】:

    标签: java gradle junit


    【解决方案1】:

    我相信我的错误是 fileTree(dir: ...)testImplemetation 中我想要的是 files(...)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-31
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多