Gradle Add Sub-Module Src path under weaving AspectJ [ant:iajc] [error] build config error: bad sourceroot: /Users/abcd/mainApp/src/main/java

huangapple go评论129阅读模式
英文:

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-modulelib-modulelib-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)
    }
}

huangapple
  • 本文由 发表于 2020年8月26日 20:16:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63597483.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定