Gradle: 构建时将子项目文件复制到根项目中
Gradle: copy subprojects files into rootproject when build it
鉴于此 gradle 项目:
org.mycompany.rootProject
|
|--org.mycompany.subProject0001
| |
| |-src/
| | |
| | |-dist/
| | | |
| | | |-README.MD
| | | |-runSubProject0001.cmd
| | |-main/
| | |-test/
| | |
| |-build.gradle
|
|--org.mycompany.subProject0002
| | |
| | |-dist/
| | | |
| | | |-README.MD
| | | |-runSubProject0002.cmd
| | |-main/
| | |-test/
| | |
| |-build.gradle
| .
| .
| . (goal is keeping going until subproject 1000)
|-build.gradle
|-settings.gradle
当我构建它时,如何从每个子项目中获取 README 和 'runSubProject' 并将其复制到我的根项目(目标是“{rootProject}/build/distribution/{subprojectName}/”)?
我所有的项目都使用“java-application”插件。
我试图 gradle 遍历每个子项目并将这些文件复制到我的根项目中,但我失败了。
所以这就是我在 org.mycompany.rootProject
的 build.gradle
中所做的并且它起作用了:
task getArtifactsFromSubprojects {
subprojects.each {
if(it.getName().contains("cjv")){
dependsOn it.getPath() + ':convertReadmeToPdf'
def sourcePath = it.getProjectDir().toString() + '/src/dist'
def destinationPath = getRootDir().toString() + '/src/dist/' + it.getName() + '/'
it.copy {
from sourcePath
into destinationPath
}
}
}
}
PS:我在我的子项目上做了一些工作,并实施了一个名为 convertReadmeToPdf
的新任务,它在与 README.MD
相同的文件夹中生成了一个 README.PDF
。
完成运行这个任务后,结果是这样的:
org.mycompany.rootProject
|
|--src/
| |
| |-dist/
| | |
| | |-org.mycompany.subProject0001/
| | | |
| | | |-README.MD
| | | |-runSubProject0001.cmd
| | |
| | |-org.mycompany.subProject0002/
| | | |
| | | |-README.MD
| | | |-runSubProject0002.cmd
| | |
| | |-org.mycompany.subProject0003/
| | | |
| | | |-README.MD
| | | |-runSubProject0003.cmd
| | .
| | .
| | .
| |
| |-main/
| |
| |-test/
|
|
|-build.gradle
|-settings.gradle
鉴于此 gradle 项目:
org.mycompany.rootProject
|
|--org.mycompany.subProject0001
| |
| |-src/
| | |
| | |-dist/
| | | |
| | | |-README.MD
| | | |-runSubProject0001.cmd
| | |-main/
| | |-test/
| | |
| |-build.gradle
|
|--org.mycompany.subProject0002
| | |
| | |-dist/
| | | |
| | | |-README.MD
| | | |-runSubProject0002.cmd
| | |-main/
| | |-test/
| | |
| |-build.gradle
| .
| .
| . (goal is keeping going until subproject 1000)
|-build.gradle
|-settings.gradle
当我构建它时,如何从每个子项目中获取 README 和 'runSubProject' 并将其复制到我的根项目(目标是“{rootProject}/build/distribution/{subprojectName}/”)?
我所有的项目都使用“java-application”插件。
我试图 gradle 遍历每个子项目并将这些文件复制到我的根项目中,但我失败了。
所以这就是我在 org.mycompany.rootProject
的 build.gradle
中所做的并且它起作用了:
task getArtifactsFromSubprojects {
subprojects.each {
if(it.getName().contains("cjv")){
dependsOn it.getPath() + ':convertReadmeToPdf'
def sourcePath = it.getProjectDir().toString() + '/src/dist'
def destinationPath = getRootDir().toString() + '/src/dist/' + it.getName() + '/'
it.copy {
from sourcePath
into destinationPath
}
}
}
}
PS:我在我的子项目上做了一些工作,并实施了一个名为 convertReadmeToPdf
的新任务,它在与 README.MD
相同的文件夹中生成了一个 README.PDF
。
完成运行这个任务后,结果是这样的:
org.mycompany.rootProject
|
|--src/
| |
| |-dist/
| | |
| | |-org.mycompany.subProject0001/
| | | |
| | | |-README.MD
| | | |-runSubProject0001.cmd
| | |
| | |-org.mycompany.subProject0002/
| | | |
| | | |-README.MD
| | | |-runSubProject0002.cmd
| | |
| | |-org.mycompany.subProject0003/
| | | |
| | | |-README.MD
| | | |-runSubProject0003.cmd
| | .
| | .
| | .
| |
| |-main/
| |
| |-test/
|
|
|-build.gradle
|-settings.gradle