Create jar with dependencies and excluding specific source files

眉间皱痕 提交于 2020-01-25 15:14:24

问题


I would like to use Maven to create a jar that includes a specific dependent artifact and excludes some of the source java files.

Currently I use this snippet:

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

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?


回答1:


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>


来源:https://stackoverflow.com/questions/26212553/create-jar-with-dependencies-and-excluding-specific-source-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!