标签: maven-shade-plugin

如何配置maven shade插件以在我的jar中包含测试代码?

我使用shade maven插件来构建我的项目,以便它的所有依赖项都包含在一个jar中(这使得在Hadoop上运行它更容易).默认情况下,Shade似乎排除了我的测试代码,这是可以理解的.由于我想对我的集群运行集成测试,我希望设置另一个配置文件来为此目的构建一个单独的jar.有没有办法配置这个插件还包括测试代码?

java hadoop maven maven-shade-plugin

13
推荐指数
4
解决办法
1万
查看次数

Maven Shade Plugin生产两个罐子

直到现在我使用maven程序集插件为每个工件生成两个JAR - 编译源和依赖项 - 原因很简单 - 仅通过网络部署已编译的源比使用40 MB部署一体式JAR要快得多数据的.

由于覆盖了内部文件,我不得不切换maven shade插件才能使用该<transformers>功能.但是我无法管理两个执行:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <id>shade-libs</id>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile>
          <artifactSet>
            <excludes>
              <exclude>...</exclude>
            </excludes>
          </artifactSet>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/spring.handlers</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/spring.schemas</resource>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <id>shade-main</id>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <outputFile>target/assembly/${project.artifactId}.jar</outputFile>
          <artifactSet>
            <includes>
              <include>...</include>
            </includes>
          </artifactSet>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

当我运行时mvn package,只运行第二次执行.第一个总是被忽略.使用maven程序集插件,它运行得很好.

当然解决方案可能是同时使用装配和阴影插件,但我想找到更一致的解决方案.

maven maven-assembly-plugin maven-shade-plugin

13
推荐指数
1
解决办法
9059
查看次数

使用maven-bundle-plugin和maven-shade-plugin

我正在使用maven-shade-plugin在我的构建的包阶段重新定位一些包.我也使用maven-bundle-plugin来生成清单.问题是bundle插件在shade插件之前运行(在进程类阶段),并且在生成的manifest的导出中不包含任何阴影包.

我怎样才能使这两个插件彼此玩得很好,这样我的重定位包就像bundle插件一样对待任何其他包?

-

根据要求,我的POM的Shade和bundle部分:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <filters>
        <filter>
          <artifact>cglib:cglib</artifact>
          <includes>
            <include>net/sf/cglib/core/**</include>
            <include>net/sf/cglib/proxy/**</include>
          </includes>
        </filter>
      </filters>
      <relocations>
        <relocation>
          <pattern>net.sf.cglib</pattern>
          <shadedPattern>org.modelmapper.internal.cglib</shadedPattern>
        </relocation>
        <relocation>
          <pattern>org.objectweb.asm</pattern>
          <shadedPattern>org.modelmapper.internal.asm</shadedPattern>
        </relocation>
      </relocations>
    </configuration>
  </plugin>

  <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.3.7</version>
    <executions>
      <execution>
        <id>bundle-manifest</id>
        <phase>process-classes</phase>
        <goals>
          <goal>manifest</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <instructions>
        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
        <Export-Package>
          org.modelmapper,
          org.modelmapper.builder,
          org.modelmapper.config,
          org.modelmapper.convention,
          org.modelmapper.spi
        </Export-Package>
        <Private-Package>
          org.modelmapper.internal.**
        </Private-Package>
        <Import-Package>
          *
        </Import-Package>
        <Include-Resource>
          {maven-resources},
          {maven-dependencies}
        </Include-Resource>
      </instructions>
    </configuration>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

采取从这里

osgi maven maven-shade-plugin maven-bundle-plugin

13
推荐指数
2
解决办法
4222
查看次数

在多模块项目中使用Maven shade插件 - NullPointerException

我有一个场景,我需要创建一个包含所有模块及其依赖项的多模块maven项目的超级jar.我尝试使用maven shade插件.但它似乎只有在模块级别使用它时才有效.如果我在父pom中添加插件条目,那么构建中断(它会尝试遮蔽父pom)

 [INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing null with C:\Projects\foo.bar\target\foobar-0.0.1-SNAPSHOT-shaded.pom
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error creating shaded jar: null: NullPointerException -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

它似乎有意义,因为<packaging>父母maven项目是pom.但应该有一些方法为多模块项目创建一个超级jar ...任何想法人???

uberjar maven maven-shade-plugin

12
推荐指数
1
解决办法
1万
查看次数

Maven遮阳罐抛出异常

我有以下例外:

线程"main"中的异常java.lang.SecurityException:在sun.security的sun.security.util.SignatureFileVerifier.verifySection(SignatureFileVerifier.java:380)中没有签名文件条目javax/security/cert/CertificateException.class的最明显部分. util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:231)位于java.util的java.util.jar.JarVerifier.processEntry(JarVerifier.java:288)的sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:176) .jar.JarVerifier.update(JarVerifier.java:199)位于sun的java.util.jar.JarFile.getInputStream(JarFile.java:388)的java.util.jar.JarFile.initializeVerifier(JarFile.java:323). misc.URLClassPath $ JarLoader $ 2.getInputStream(URLClassPath.java:692)位于sun.net的sun.misc.Resource.getByteBuffer(Resource.java:144)的sun.misc.Resource.cachedInputStream(Resource.java:61). URLClassLoader.defineClass(URLClassLoader.java:256)at java.net.URLClassLoader.access $ 000(URLClassLoader.java:58)at java.net.URLClassLoader $ 1.run(URLCl)assLoader.java:197)java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:190)at java.lang.ClassLoader.loadClass(ClassLoader.java:306)at sun .misc.Launcher $ AppClassLoader.loadClass(Launcher.java:301)at java.lang.ClassLoader.loadClass(ClassLoader.java:247)找不到主类:com.mainClass.程序将会退出.

我的pom:

<plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                <version>1.5</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filter>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.mainClass</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
Run Code Online (Sandbox Code Playgroud)

exception maven maven-shade-plugin

12
推荐指数
2
解决办法
5934
查看次数

像SBT一样的maven-shade插件

我是scala和sbt世界的新手,我正在尝试用sbt管理我所有的新项目,而不是使用maven.但是现在我正处于一个我不太了解的地步,因为我找不到mavnen-shade插件的任何对应物.我发现只有插件包含所有依赖项,但这不是我需要的.那么有人知道一个插件将某些依赖项包含在jar中吗?

scala sbt maven-shade-plugin

12
推荐指数
1
解决办法
3690
查看次数

如何从阴影jar中排除*.DSA和*.SF文件?

我在pom.xml中有一节

 <filters>
   <filter>
      <artifact>*:*</artifact>
         <excludes>
            <exclude>META-INF/*.SF</exclude>
            <exclude>META-INF/*.DSA</exclude>
         </excludes>
   </filter>
</filters>
Run Code Online (Sandbox Code Playgroud)

我想从最终jar中排除*.SF和*.DSA文件.但我收到以下消息:

[INFO] No artifact matching filter *:*
Run Code Online (Sandbox Code Playgroud)

和文件不排除.有谁知道如何克服它?

java maven maven-shade-plugin

11
推荐指数
2
解决办法
6883
查看次数

禁用maven-shade-plugin的其他jar

我正在使用maven-shade-plugin创建一个可执行的jar.我希望插件foo.jar在目标目录中创建一个jar().然而,它还将创建另外两个罐子:original-foo.jarfoo-shaded.jar.

为什么创建这些文件以及如何禁用此行为?

(我们有另一个使用该插件的项目,其中没有创建这些文件.因此我很确定可以禁用它们,但我看不出其中的区别.)

maven maven-shade-plugin

11
推荐指数
2
解决办法
3090
查看次数

阴影/重新打包的jar作为依赖项

在这种情况下,我们需要一个应用程序才能连接到两个版本的kafka(0.7.2和0.10.0+)并充当路由器。我试图在这里省略使用两个运行时,因为我们需要快速愚蠢,因此在运行时之间发送数据时要防止额外的序列化/反序列化。

为此,我尝试将旧的kafka驱动程序从软件包kafka重新打包为old.kafka,如下所示:

<?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">
    <parent>
        <artifactId>kafka-router</artifactId>
        <groupId>org.deer</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>old-kafka</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <kafka.version>0.7.2</kafka.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.apache.kafka</groupId>
                                    <artifactId>kafka_2.9.2</artifactId>
                                    <version>${kafka.version}</version>
                                    <type>jar</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${project.build.directory}/classes</outputDirectory>
                                    <includes>**/*.class,**/*.xml</includes>
                                </artifactItem>
                            </artifactItems>
                            <includes>**/*.java</includes>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>kafka.</pattern>
                                    <shadedPattern>old.kafka.</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build> …
Run Code Online (Sandbox Code Playgroud)

java maven maven-shade-plugin apache-kafka

11
推荐指数
1
解决办法
324
查看次数

Maven Shade 插件:如何解决警告消息“定义 1 重叠资源:[警告] - META-INF/MANIFEST.MF”

为了

  <dependencies>
    ...
    <dependency>
        <groupId>com.manuel.jordan</groupId>
        <artifactId>some module</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    ... 
  </dependencies>

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version>
            <executions>
                <execution>
                    <id>create-fat-jar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <finalName>somename</finalName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>
Run Code Online (Sandbox Code Playgroud)

该插件运行良好,但总是出现此消息:

[WARNING] moduleA-0.0.1-SNAPSHOT.jar, 
          moduleB-0.0.1-SNAPSHOT.jar, 
          .... more
          moduleN-0.0.1-SNAPSHOT.jar define 1 overlapping resource: 
[WARNING]   - META-INF/MANIFEST.MF
[WARNING] maven-shade-plugin has detected that some class files are
[WARNING] present in two or more JARs. When this happens, only one
[WARNING] single version of the class is copied to the uber jar.
[WARNING] …
Run Code Online (Sandbox Code Playgroud)

maven-3 maven maven-shade-plugin

11
推荐指数
2
解决办法
9489
查看次数