Gradle : Exclude file creating jar in a subproject

独自空忆成欢 提交于 2019-12-11 19:09:55

问题


I have a multi-module-project. The structure is as follows.

root-project
------------
├── project-A
│   └── src
│       └── main
│           └── resources
│               └── myFile.xml
├── project-B
│   └── src
│       └── main
│           └── resources
│               └── myFile.xml
└── project-shared
    └── src
        └── main
            └── resources
                └── myFile.xml

(':project-A') is depends on (':project-shared') and (':project-B')
My issue is when I build (':project-A')

I have a filtertocken (to replace version number) in myFile.xml. So I need myFile.xml under project-A to be in project-A.jar file. But unfortunately project-A.jar contains myFile.xml from project-shared. I tried removing myFile.xml from project-shared and then while building project-A , the project-A jar contains myFile.xml from project-B.

I need myFile.xml file in project-A.jar whenever I build it. Is there any way ?

code is as follows:

processResources() {
    java.lang.String version        = project.version
    filter(ReplaceTokens, tokens: ['VERSION': version])
}

dependencies { 
compile project(':project-shared')
compile project(':project-B')
...
...
}

//Tried different ideas..
tasks['compileJava'].dependsOn      += [processResources]
tasks['installHost'].dependsOn      += [processResources]
tasks['jar'].dependsOn              += [processResources]

Is there any way to exclude the following files while building project-A ?
1. project-B/src/main/resources/myFile.xml
2. project-shared/src/main/resources/myFile.xml
Or Only keep project-A/src/main/resources/myFile.xml always in project-A.jar

来源:https://stackoverflow.com/questions/33014820/gradle-exclude-file-creating-jar-in-a-subproject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!