创建具有依赖项并排除特定源文件的 jar [英] Create jar with dependencies and excluding specific source files
问题描述
我想使用 Maven 创建一个包含特定依赖工件并排除一些源 java 文件的 jar.
I would like to use Maven to create a jar that includes a specific dependent artifact and excludes some of the source java files.
目前我使用这个片段:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>shadedJar</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedClassifierName>classifier</shadedClassifierName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>com.google.guava:guava</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
因此,jar 确实包含番石榴"工件文件,但是我还想排除一些源文件(例如 src/main/java/my.package/下的特定文件),我该怎么做?
Thus, the jar does contain the 'guava' artifact files, however I would also like to exclude some source files (for example a specific file under src/main/java/my.package/), How can I do that?
推荐答案
我使用 shade 来创建一个 jar,但我不需要一些 eclipse、txt 和其他只与开发相关的东西.
I use shade to create a jar, but I do not need some files of eclipse, txt and other things that they are relevant only to development.
这是我的代码,也许你可以添加并使用它.
This is the code I have, maybe you can addapt it and use it.
<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>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>.settings/**</exclude>
<exclude>*.classpath</exclude>
<exclude>*.project</exclude>
<exclude>*.txt</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
这篇关于创建具有依赖项并排除特定源文件的 jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!