gpt4 book ai didi

多项目上的 gradle sourceSets

转载 作者:行者123 更新时间:2023-12-02 04:14:37 40 4
gpt4 key购买 nike

我的gradle多项目布局是这样的:

rootProject
|-- project1
|
|-- project2
|
|-- src
| |-- main
| | |-- groovy
| | `-- resources
| |-- test
| | |-- groovy
| | `-- resources
| `-- sanity
| |-- groovy
| `-- resources
|
|---- settings.gradle
`---- build.gradle

project1和project2在build.gradle(在rootProject中)中配置。
我想将project1和project2 testClassDir 更改为sanity

我的build.gradle是这样的:

subprojects{
apply plugin: "groovy"

sourceSets {
sanity {
groovy.srcDir "src/sanity/groovy"
resources.srcDir "src/sanity/resources"
}
}

dependencies {
sanityCompile sourceSets.main.output
sanityCompile sourceSets.test.output

sanityCompile configurations.compile
sanityCompile configurations.testCompile

sanityRuntime configurations.runtime
sanityRuntime configurations.testRuntime
}
runTest {
testClassesDir = sourceSets.sanity.output.classesDir
classpath = sourceSets.sanity.runtimeClasspath
}
}

project('project1) {
}

我已经关注了这个Blog ,我试图理解为什么该配置不适用于多项目。

最佳答案

我已经找到解决办法了。我需要将根项目中的源集定义到新的测试文件夹。在子项目中,我需要将测试目录设置为 rootProject。新的build.gradle:

// On root project
sourceSets {
sanity {
groovy.srcDir "src/sanity/groovy"
resources.srcDir "src/sanity/resources"
}
}

dependencies {
sanityCompile sourceSets.main.output
sanityCompile sourceSets.test.output

sanityCompile configurations.compile
sanityCompile configurations.testCompile

sanityRuntime configurations.runtime
sanityRuntime configurations.testRuntime
}

subprojects {
apply plugin: "groovy"

runTest {
// Redirect the class dir to rootProject
testClassesDir = rootProject.sourceSets.sanity.output.classesDir
classpath = rootProject.sourceSets.sanity.runtimeClasspath
}
}

project('project1) {
}

project('project2) {
}

关于多项目上的 gradle sourceSets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42420776/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com