将另一个java源目录添加到gradle脚本 [英] Add another java source directory to gradle script
问题描述
package com.example.testing;
带有这样的文件树
app
|
src-> com-> example-> testing-> Main.java
和一个gradle脚本:
apply plugin:'java'
apply plugin:'application'
sourceSets {
main {
java {
srcDirs'src'
}
}
}
sourceSets.main.output.classesDir = file(classes)
mainClassName ='com.example.testing.Main'
defaultTasks'compileJava', 'run'
现在我想添加一些模块到这个项目中,我的文件夹就像这样
app
|
src1-> com-> example-> testing-> Main.java
src2-> com-> another_example-> another_testing-> Library.java
如何将新的源代码添加到gradle脚本中?
我同意@JB Nizet关于尊重标准的约定。不过,如果你仍然坚持要成为无政府主义者:
你已经在你的源代码集中声明了 src
,为什么不添加 src1
和 src2
以及?您可以将它们添加到相同的源代码集,或者根据需要定义每个模块的源代码集。
sourceSets {
main {
java {
srcDirs'src'
srcDirs'src1'
srcDirs'src2'
}
}
}
I hava an example java project package
package com.example.testing;
with such file tree
app
|
src->com->example->testing->Main.java
and a gradle script:
apply plugin: 'java'
apply plugin: 'application'
sourceSets {
main {
java {
srcDirs 'src'
}
}
}
sourceSets.main.output.classesDir = file("classes")
mainClassName = 'com.example.testing.Main'
defaultTasks 'compileJava', 'run'
Now I want to add some module to this project and my folders will be something like this
app
|
src1->com->example->testing->Main.java
src2->com->another_example->another_testing->Library.java
How do I add new source code to gradle script?
I agree with @JB Nizet about respecting standard conventions. If you still insist on being an Anarchist though:
You already have src
declared in your sourceset, why not add src1
and src2
as well? You can add them to the same sourceset, or define a sourceset per module if you want.
sourceSets {
main {
java {
srcDirs 'src'
srcDirs 'src1'
srcDirs 'src2'
}
}
}
这篇关于将另一个java源目录添加到gradle脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!