java Gradle 能否处理不符合默认约定的构建目录结构?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2551463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can Gradle handle a build directory structure that does not conform default conventions?
提问by liam.j.bennett
I am working on a javaant+ivybased project that has the following directory structure:
我正在开发一个基于java ant+ ivy的项目,该项目具有以下目录结构:
projectRoot/src
projectRoot/classes
projectRoot/conf
projectRoot/webservices
this works perfectly well in antbut I am looking to migrate to gradle.
Is there a way to define a non-maven directory structure in Gradle or should I be looking to mavenize?
有没有办法在 Gradle 中定义非 maven 目录结构,或者我应该寻找mavenize吗?
回答by Hans Dockter
It is very easy with Gradle to adapt to any directory structure. See the Working with source setssection of the Gradle User Guide.
Gradle 很容易适应任何目录结构。请参阅Gradle 用户指南的使用源集部分。
回答by Dimitar II
Example with non-standard project directory structure (custom layout):
具有非标准项目目录结构的示例(自定义布局):
sourceSets {
main {
java {
srcDir 'sources/main/java'
}
outputDir = file("$workDir/client/program")
// For older version (now deprecated):
//output.classesDir = "$workDir/client/program"
}
test {
java {
srcDir 'sources/test/java'
}
outputDir = file("$workDir/client/tests")
// For older versions (now deprecated):
//output.classesDir = "$workDir/client/tests"
//output.resourcesDir = "$workDir/client/tests"
}
resources {
srcDirs 'sources/test/res'
}
}
回答by Hasan A Yousef
Try:
尝试:
sourceSets {
main {
java {
srcDirs = ['src/java']
}
resources {
srcDirs = ['src/resources']
}
}
}
or
或者
sourceSets {
main.java.srcDirs += 'src/java'
main.resources.srcDirs += 'src/resources'
}

