我正在将 JAVA maven 项目迁移到 gradle。我在 maven 中添加了一个 Shade 插件,但是当我试图在 gradle 中复制它时,它目前失败了。它在清理时失败,即当我发出以下命令时,
gradle clean
请在下面找到 pom.xml 文件和相应的 build.gradle 文件。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproj.integration</groupId>
<artifactId>Generic-Integration</artifactId>
<name>Generic-Integration</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<finalName>myproj-integration-${project.version}</finalName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>jersey.repackaged</pattern>
<shadedPattern>myproj.repackaged</shadedPattern>
</relocation>
<relocation>
<pattern>javassist</pattern>
<shadedPattern>myproj.repackaged.javassist</shadedPattern>
</relocation>
<relocation>
<pattern>org.aopalliance</pattern>
<shadedPattern>myproj.repackaged.org.aopalliance</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.logging</pattern>
<shadedPattern>myproj.repackaged.org.apache.logging</shadedPattern>
</relocation>
<relocation>
<pattern>org.codehaus.jackson</pattern>
<shadedPattern>myproj.repackaged.org.codehaus.jackson</shadedPattern>
</relocation>
<relocation>
<pattern>org.glassfish.hk2</pattern>
<shadedPattern>myproj.repackaged.org.glassfish.hk2</shadedPattern>
</relocation>
<relocation>
<pattern>org.glassfish.jersey</pattern>
<shadedPattern>myproj.repackaged.org.glassfish.jersey</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>myproj.repackaged.org.json</shadedPattern>
</relocation>
<relocation>
<pattern>org.jvnet</pattern>
<shadedPattern>myproj.repackaged.org.jvnet</shadedPattern>
</relocation>
<relocation>
<pattern>javax.annotation</pattern>
<shadedPattern>myproj.repackaged.javax.annotation</shadedPattern>
</relocation>
<relocation>
<pattern>javax.inject</pattern>
<shadedPattern>myproj.repackaged.javax.inject</shadedPattern>
</relocation>
<relocation>
<pattern>javax.ws</pattern>
<shadedPattern>myproj.repackaged.javax.ws</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.myproj.integration.ServiceExecuter</mainClass>
</transformer>
</transformers>
<artifactSet>
<includes>
<include>com.myproj:Util</include>
<include>org.glassfish.hk2:hk2-api</include>
<include>org.glassfish.hk2:hk2-utils</include>
<include>org.glassfish.hk2:hk2-locator</include>
<include>org.glassfish.hk2:osgi-resource-locator</include>
<include>org.glassfish.hk2.external:aopalliance-repackaged</include>
<include>org.codehaus.jackson:jackson-core-asl</include>
<include>org.codehaus.jackson:jackson-mapper-asl</include>
<include>org.codehaus.jackson:jackson-jaxrs</include>
<include>org.codehaus.jackson:jackson-xc</include>
<include>org.javassist:javassist</include>
<include>javax.annotation:javax.annotation-api</include>
<include>org.glassfish.hk2.external:javax.inject</include>
<include>javax.ws.rs:javax.ws.rs-api</include>
<include>org.glassfish.jersey.core:jersey-client</include>
<include>org.glassfish.jersey.core:jersey-common</include>
<include>org.glassfish.jersey.bundles.repackaged:jersey-guava</include>
<include>org.glassfish.jersey.media:jersey-media-json-jackson</include>
<include>org.json:json</include>
<include>com.myproj:JAXRS</include>
</includes>
</artifactSet>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.myproj</groupId>
<artifactId>JAXRS</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>8.1.16.v20140903</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.myproj</groupId>
<artifactId>Server</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>
</dependencies>
构建.gradle
plugins {
id 'com.github.johnrengelman.shadow' version '1.2.3'
}
shadowJar {
artifactSet {
include 'com.myproj:Util'
include 'org.glassfish.hk2:hk2-api'
include 'org.glassfish.hk2:hk2-utils'
include 'org.glassfish.hk2:hk2-locator'
include 'org.glassfish.hk2:osgi-resource-locator'
include 'org.glassfish.hk2.external:aopalliance-repackaged'
include 'org.codehaus.jackson:jackson-core-asl'
include 'org.codehaus.jackson:jackson-mapper-asl'
include 'org.codehaus.jackson:jackson-jaxrs'
include 'org.codehaus.jackson:jackson-xc'
include 'org.javassist:javassist'
include 'javax.annotation:javax.annotation-api'
include 'org.glassfish.hk2.external:javax.inject'
include 'javax.ws.rs:javax.ws.rs-api'
include 'org.glassfish.jersey.core:jersey-client'
include 'org.glassfish.jersey.core:jersey-common'
include 'org.glassfish.jersey.bundles.repackaged:jersey-guava'
include 'org.glassfish.jersey.media:jersey-media-json-jackson'
include 'org.json:json'
include 'com.myproj:JAXRS'
}
relocation {
pattern = 'jersey.repackaged'
shadedPattern = 'myproj.repackaged'
}
relocation {
pattern = 'javassist'
shadedPattern = 'myproj.repackaged.javassist'
}
relocation {
pattern = 'org.aopalliance'
shadedPattern = 'myproj.repackaged.org.aopalliance'
}
relocation {
pattern = 'org.apache.logging'
shadedPattern = 'myproj.repackaged.org.apache.logging'
}
relocation {
pattern = 'org.codehaus.jackson'
shadedPattern = 'myproj.repackaged.org.codehaus.jackson'
}
relocation {
pattern = 'org.glassfish.hk2'
shadedPattern = 'myproj.repackaged.org.glassfish.hk2'
}
relocation {
pattern = 'org.glassfish.jersey'
shadedPattern = 'myproj.repackaged.org.glassfish.jersey'
}
relocation {
pattern = 'org.json'
shadedPattern = 'myproj.repackaged.org.json'
}
relocation {
pattern = 'org.jvnet'
shadedPattern = 'myproj.repackaged.org.jvnet'
}
relocation {
pattern = 'javax.annotation'
shadedPattern = 'myproj.repackaged.javax.annotation'
}
relocation {
pattern = 'javax.inject'
shadedPattern = 'myproj.repackaged.javax.inject'
}
relocation {
pattern = 'javax.ws'
shadedPattern = 'myproj.repackaged.javax.ws'
}
}
dependencies {
compile project(':JAXRS')
compile project(':Server')
testCompile group: 'org.testng', name: 'testng', version:'6.8.8'
compile(group: 'org.eclipse.jetty', name: 'jetty-servlet', version:'8.1.16.v20140903') {
/* This dependency was originally in the Maven provided scope, but the project was not of type war.
This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
Please review and delete this closure when resolved. */
}
}
task genericIntegrationJar(type: Jar) {
baseName = 'myproj-integration-1.2'
from { configurations.external.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
test.useTestNG()
当我进行清洁时,我遇到了以下异常,
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/mac8/POS/MobilePosSolution/Generic-Integration/build.gradle' line: 2
* What went wrong:
Error resolving plugin [id: 'com.github.johnrengelman.shadow', version: '1.2.3']
> The response from https://plugins.gradle.org/api/gradle/2.14.1/plugin/use/com.github.johnrengelman.shadow/1.2.3 was not a valid response from a Gradle Plugin Resolution Service: content type is 'text/html;charset=iso-8859-1', expected 'application/json' (status code: 404)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.903 secs
请让我知道是否需要在build.gradle文件中更改某些内容以复制阴影插件。