我的 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/