![](/img/trans.png)
[英]Gradle transitive dependencies of a subproject used in another subproject
[英]Adding subproject resolved dependencies to earlib in gradle 5.5.1
我有一个包含100多个EAR文件的多项目构建。 子项目或多或少使用如下约定:
subproject1
-| subproject1JAR
-| subproject1EAR
-| subproject1WAR
subproject2
-| subproject2JAR
-| subproject2EAR
-| subproject2WAR
当我在下面提到JAR时,我指的是包含在例如subproject1.jar
的业务逻辑/ SDK。
我在subprojects{}
中的afterEvaluate
块中有一些逻辑subprojects{}
,该afterEvaluate
分析subprojects{}
的.classpath
文件以构建EAR文件。 这是可行的,但是与传统(手动)构建相比,我没有得到的一件事是EAR / lib文件夹需要包含JAR文件的所有依赖关系。
不好意思,我只是想提供此问题的完整上下文。
// this is from subprojects
if(proj.projectDir.name.endsWith('EAR')){ <-- configures EAR proj based on folder name
proj.apply plugin: 'ear'
proj.ear {
baseName = proj.projectDir.name
// snip other ear config stuff
}
if(f_ui.exists()){ // <-- f_ui is a File pointed at what ought to be the WAR subproject
proj.dependencies{
deploy project(path:":${proj_war}WAR", configuration:'archives')
}
}
if(f_jar.exists()){ // <-- f_jar is a File pointed at what ought to be the JAR subproject
proj.dependencies{
earlib project(path:":$proj_jar", configuration:'archives')
}
def jar_proj = project(":$proj_jar")
proj.evaluationDependsOn(":$proj_jar")
jar_proj.configurations.runtime.allDependencies.forEach { <-- trying to add deps here but
println "##> DEPENDENCY $it" <-- these are empty here
proj.dependencies.add('earlib', it)
}
}
// ## END OF EAR PROJECT CONFIGURATION
}
您可以在上面看到我试图将JAR的依赖项添加到earlib配置的情况,但是此时似乎依赖项尚未解决,因此未添加任何依赖项。
我相信这个未解决的问题似乎在问同样的事情。
关于如何将JAR的依赖项放入ear / lib文件夹的任何建议?
我当然不认为这是最好的解决方案,但它似乎正在起作用,因此我将描述自己的工作。
创建一个自定义配置,将我需要显示在earlib
中的所有依赖项添加到其中:
subprojects { Project proj ->
def projname = proj.name
afterEvaluate {
logger.info "## {} afterevaluation #0 started",projname
["Proj1","proj2", "proj3"].each{ depson ->
if (classpathFileContains(proj,depson)) {
proj.configurations.maybeCreate('extra')
proj.dependencies.add('extra', project(":${depson}"))
}
}
...
将它们添加为实现依赖项:
try {
// if the project has 'extra', add them to the implementation
proj.configurations.named('extra')
proj.configurations.extra.dependencies.each{
proj.dependencies.add('implementation', it)
}
} catch(e) {
logger.info "## Project {} did not have an extra", proj.name
}
添加jar文件,然后从定制配置中添加其他依赖项:
proj.dependencies{
earlib project(":$proj_jar")
}
try {
jar_proj.configurations.named('extra')
jar_proj.configurations.extra.dependencies.each{
proj.dependencies.add('earlib', it.copy())
}
...
顺便说一句,我遇到了earlib
遇到此挑战的其他几个人(请参阅ex1 , ex2 , ex3以及问题中的参考文献)。
我将尝试简化操作,如果有时间,将更新此答案,但到目前为止,这种方法正在起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.