英文:
Gradle Add Sub-Module Src path under weaving AspectJ [ant:iajc] [error] build config error: bad sourceroot: /Users/abcd/mainApp/src/main/java
问题
在mainApp/build.gradle
文件中,您想要将子模块的源代码目录指定为sourceroots{}
。您可以通过以下方式实现:
compileJava {
doLast {
ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath)
ant.iajc(
maxmem: "1024m", fork: "true", Xlint: "ignore",
destDir: sourceSets.main.output.classesDirs.asPath,
aspectPath: configurations.aspects.asPath,
sourceRootCopyFilter: "**/.svn/**,**/*.java",
classpath: configurations.compile.asPath,
source: project.sourceCompatibility,
target: project.targetCompatibility
) {
sourceroots {
// 添加子模块的源代码目录到sourceroots中
sourceSets.main.java.srcDirs.each {
pathelement(location: it.absolutePath)
}
// 添加core-module的源代码目录
pathelement(location: project(":core-module").sourceSets.main.java.srcDirs.singleFile.absolutePath)
// 添加lib-module的源代码目录
pathelement(location: project(":lib-module").sourceSets.main.java.srcDirs.singleFile.absolutePath)
// 添加lib-another-module的源代码目录
pathelement(location: project(":lib-another-module").sourceSets.main.java.srcDirs.singleFile.absolutePath)
}
}
}
}
上述代码在sourceroots{}
中添加了core-module
、lib-module
和lib-another-module
的源代码目录,以便AspectJ编织可以找到这些源代码文件。这应该解决您遇到的错误。
英文:
I have a multi-module setup for a Java project with following structure.
mainApp
|--> core-module
| |--> src
| |--> build.gradle
|
|--> lib-module
| |--> src
| |--> build.gradle
|--> lib-another-module
| |--> src
| |--> build.gradle
|
|--> settings.gradle
|--> build.gradle
|--> gradle.properties
in mainApp/build.gradle
I've mentioned
compileJava {
//dependsOn configurations.ajc.getTaskDependencyFromProjectDependency(true, "compileJava")
doLast{
ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath)
ant.iajc(
maxmem: "1024m", fork: "true", Xlint: "ignore",
destDir: sourceSets.main.output.classesDirs.asPath,
aspectPath: configurations.aspects.asPath,
sourceRootCopyFilter: "**/.svn/*,**/*.java",
classpath: configurations.compile.asPath,
source: project.sourceCompatibility,
target: project.targetCompatibility
){
sourceroots{
sourceSets.main.java.srcDirs.each{
pathelement(location:it.absolutePath)
}
}
}
}
}
I'm getting error as [ant:iajc] [error] build config error: bad sourceroot: /Users/abcd/mainApp/src/main/java
How can I point sub-module
src to sourceroots{}
?
答案1
得分: 0
我能够解决这个问题。基本上我的根项目没有任何源代码(它只是一个父级Gradle模块容器),因此需要从“sourceRoots”中省略掉。
sourceroots {
sourceSets.main.java.srcDirs.each {
if (!it.absolutePath.contains("/src/main/java")) {
pathelement(location: it.absolutePath)
}
}
}
英文:
I'm able to sort out the issue. Basically my root-project doesn't have any source-code(It's just a parent Gradle module container) so, it is required to be omitted from sourceRoots
sourceroots{
sourceSets.main.java.srcDirs.each{
if(!it.absolutePath.contains("/src/main/java")) {
pathelement(location: it.absolutePath)
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论