【问题标题】:Create jar with dependencies and excluding specific source files创建具有依赖项并排除特定源文件的 jar
【发布时间】:2014-10-06 08:37:15
【问题描述】:

我想使用 Maven 创建一个 jar,其中包含特定的依赖工件并排除一些源 java 文件。

目前我用这个sn-p:

            <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 确实包含“guava”工件文件,但是我还想排除一些源文件(例如 src/main/java/my.package/ 下的特定文件),我该怎么做?

【问题讨论】:

  • 究竟是什么源文件?
  • 我想排除模块源中 /src/main/java/my.package 文件夹下的一些特定文件。

标签: java maven maven-shade-plugin


【解决方案1】:

我用shade来创建一个jar,但是我不需要一些eclipse、txt等只和开发相关的文件。

这是我的代码,也许你可以添加它并使用它。

           <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>

【讨论】:

  • @opeled 如果你能用我的通用答案解决你的问题,请将帖子标记为正确答案,然后票就完成了
猜你喜欢
  • 1970-01-01
  • 2016-06-20
  • 2017-07-19
  • 1970-01-01
  • 2020-08-19
  • 2015-09-23
  • 2020-05-18
  • 2023-03-25
  • 1970-01-01
相关资源
最近更新 更多