【问题标题】:What does gradle import fom a war dependency and how can I control/manipulate the war contents?gradle 从战争依赖项中导入什么以及如何控制/操纵战争内容?
【发布时间】:2020-08-29 23:05:52
【问题描述】:

我添加了this artifact,这是对我的 gradle 项目依赖项的一场战争。 我需要扩展一些类,并从中使用修改后的 servlet 上下文。

我期待战争按原样导入,然后我将使用 gradle 任务来操作以将 jar 包含到依赖项中,复制静态资源以更正类路径等。 但是 gradle 实际上添加了一堆 jars 来依赖。

我不确定 gradle 是否递归地扫描了 jar 和 pom 的所有路径,或者可能只是战争中 WEB-INF/classes 文件夹下的 jar。 我可以假设 poms 存储库可能不是stated here

我正确的是假设没有导入泄气战争中 WEB-INF/lib 文件夹中的罐子?很难说,因为我的项目和所讨论的战争之间有很多共享的依赖关系

如果我需要按照顶部所述进行扩展和修改,那么在 maven repo/jcenter 中声明对战争的依赖的最佳方式是什么?

更新:

我现在正在尝试使用下面的答案和这个解决方案https://discuss.gradle.org/t/how-to-add-an-artifactory-war-as-a-gradle-dependency/19804/2 , 这仅在使用 buildDir 之外的复制 jar 移动目录后才有效 我的 build.gradle

configurations {
    warOnly
}
dependencies {   
// not working    implementation fileTree('$buildDir/explodedWar/WEB-INF/classes')
    implementation fileTree('anotherDir/explodedWar/WEB-INF/classes')
//    implementation fileTree('$buildDir/explodedWar/WEB-INF/lib')
    implementation fileTree('anotherDir/explodedWar/WEB-INF/lib')
    warOnly 'ca.uhn.hapi.fhir:hapi-fhir-jpaserver-starter:4.2.0@war'
    }
    tasks.register("explodeWar",Copy) {
        from zipTree(configurations.warOnly.singleFile)
   //     into "${buildDir}/explodedWar"
    into "anotherDir/explodedWar"
    }
    compileJava {
        dependsOn explodeWar

    }

【问题讨论】:

    标签: java maven gradle dependencies


    【解决方案1】:

    通过声明对 WAR 的依赖关系,Gradle 将简单地将其添加到匹配配置的文件列表中。因此,如果您在implementation 中添加 WAR,它只会在compileClasspathruntimeClasspath 上,无需任何处理。

    因此,Gradle 肯定不会将您的 WAR 依赖转换为对它包含的 JAR 的依赖。

    如果您想在重新打包之前使用 WAR 复制和修改其某些内容,您可以使用隔离和自定义配置从远程存储库中解析它。然后,您将定义一个 Gradle 任务,该任务将该配置文件作为输入,并在 WAR 上进行所需的处理。请注意,该任务也可以是一系列任务的起点,将 WAR 操作到一个输出,然后将该输出操作到另一个输出,等等...

    configurations {
        warOnly
    }
    dependencies {
        warOnly "com.pany:some-war:1.0"
    }
    tasks.register("copyWar", Copy) { // Register a copy task to modify the WAR
        from(zipTree(configurations.warOnly)) // I did not run this, so you may have to get to the single file instead
        // Regular copy configuration to decide a destination, perform on the fly changes, etc ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-23
      相关资源
      最近更新 更多