Gradle 从所有多项目渐变生成依赖项生成类路径

Gradle 从所有多项目渐变生成依赖项生成类路径,gradle,Gradle,我们正在使用一个外部测试工具(Squish),它在我们的主要gradle构建之后运行。这需要被测类的可见性。目前,CLASSPATH环境变量是通过各种bash脚本和其他字符串操作构建的。我的目标是让gradle自动完成这项工作 由于构建是在一个非常慢的源代码控制系统(clearcase)上完成的,因此最好针对构建留下的类文件/JAR运行测试,而不是将额外的副本/压缩到单个JAR中等 类路径需要包含 生成的JAR文件,通常位于build/libs/project-x.JAR中 测试类通常是构建/

我们正在使用一个外部测试工具(Squish),它在我们的主要gradle构建之后运行。这需要被测类的可见性。目前,CLASSPATH环境变量是通过各种bash脚本和其他字符串操作构建的。我的目标是让gradle自动完成这项工作

由于构建是在一个非常慢的源代码控制系统(clearcase)上完成的,因此最好针对构建留下的类文件/JAR运行测试,而不是将额外的副本/压缩到单个JAR中等

类路径需要包含

  • 生成的JAR文件,通常位于build/libs/project-x.JAR中
  • 测试类通常是构建/类/测试
  • 测试资源通常是构建/资源/测试
  • 任何第三方JAR都依赖于任何子项目、log4j、spring等
这是一个复杂的多项目构建,但我已经简化为下面的示例,其中包含父项目和两个子项目

父设置.gradle

include ':child1'
include ':child2'
父build.gradle

allprojects {
  apply plugin: 'java'
  repositories {
    mavenCentral()
  }
}
dependencies {
   compile 'org.springframework:spring-context:4.1.2.RELEASE'
   compile 'org.springframework:spring-beans:4.1.2.RELEASE'
}
dependencies {
   project (":child1")
}
儿童1.gradle

allprojects {
  apply plugin: 'java'
  repositories {
    mavenCentral()
  }
}
dependencies {
   compile 'org.springframework:spring-context:4.1.2.RELEASE'
   compile 'org.springframework:spring-beans:4.1.2.RELEASE'
}
dependencies {
   project (":child1")
}
儿童2.gradle

allprojects {
  apply plugin: 'java'
  repositories {
    mavenCentral()
  }
}
dependencies {
   compile 'org.springframework:spring-context:4.1.2.RELEASE'
   compile 'org.springframework:spring-beans:4.1.2.RELEASE'
}
dependencies {
   project (":child1")
}
到目前为止我得到了什么。这是正确的方法吗?它能以更好的方式简化或完全重写吗

task createSquishClasspath << {
  def paths = new LinkedHashSet()
  paths.addAll(subprojects.configurations.compile.resolvedConfiguration.resolvedArtifacts.file.flatten())
  paths.addAll(subprojects.jar.outputs.files.asPath)
  paths.addAll(subprojects.sourceSets.test.output.resourcesDir)
  paths.addAll(subprojects.sourceSets.test.output.classesDir)

  paths.each {
    println "${it}"
  }

  println paths.join(File.pathSeparator)

}
task createSquishClasspath << {
  def paths = new LinkedHashSet()
  paths.addAll(subprojects.configurations.compile.resolvedConfiguration.resolvedArtifacts.file.flatten())
  paths.addAll(subprojects.jar.outputs.files.asPath)
  paths.addAll(subprojects.sourceSets.test.output.resourcesDir)
  paths.addAll(subprojects.sourceSets.test.output.classesDir)

  paths.each {
    println "${it}"
  }

  println paths.join(File.pathSeparator)

}

总之,到目前为止,最好的答案是将项目依赖项的所有路径以及所有
test.output.resourcesDir
test.output.classesDir

task createSquishClasspath