java - 构建 war 时创建额外的 jar

标签 java gradle

我的 gradle 构建脚本有一个依赖项:

apply plugin 'war'

dependencies {
    compile 'com.github.jsimone:webapp-runner:7.0.22'
}

创建 war 时,任务 createWebappRunnerJar 是否可以从给定的远程源创建 jar?

我正在查看http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.Jar.html但我不认为它是为了用于远程源。

webapp-runner 内置于 war 中,如果无法从远程源构建它,也许有办法以某种方式将其从 war 中复制出来?

在 Maven 中,以下代码执行相同的操作:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>copy</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>com.github.jsimone</groupId>
                        <artifactId>webapp-runner</artifactId>
                        <version>7.0.22</version>
                        <destFileName>webapp-runner.jar</destFileName>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

最佳答案

您最好的选择是仅为您打算作为远程源包含的依赖项创建一个单独的配置,然后创建一个复制任务,将该配置复制到您选择的位置。

configurations {
    remoteSources {
        transitive false
    }
}

dependencies {
    remoteSources 'com.github.jsimone:webapp-runner:7.0.22'
}

task copyRemoteSources(type: Copy) {
    from configurations.remoteSources
    into "${project.buildDir}/remoteSources"
}

关于java - 构建 war 时创建额外的 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25548874/

相关文章:

java - 使用 File.listFiles() 时出现 IntelliJ "may cause NullPointerException"警告

plugins - Gradle:重新初始化/重新加载settings.gradle

spring-boot - 在intellij中运行并执行jar时的微妙差异

android - Gradle - 哪个任务创建了 'build' 目录?

gradle - 为什么一个项目依赖被另一个已经存在的依赖替换

java - 忽略 JAX-WS 客户端中缺少的方法

java - 查询数据库并以 Json 格式返回结果的通用 Java 方法

android - MainActivity.java中的NonNull问题

java - 如何从单个文件保存多个对象?

java - 是否可以为 Tomcat 使用相同的代码库?