Maven从依赖性中排除文件

时间:2019-06-11 16:06:59

标签: java maven maven-assembly-plugin

我有2个项目(项目A,项目B)依赖于同一项目(项目C)。

项目A

<?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.exemple.test</groupId>
    <artifactId>ProjectA</artifactId>
    <version>1.5-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Project A</name>
    ...
    <dependencies>
        ... 
        <dependency>
            <groupId>com.exemple.test</groupId>
            <artifactId>ProjectC</artifactId>
        </dependency>
        ...
    </dependencies>
    ...

</project>

项目B

<?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.exemple.test</groupId>
    <artifactId>ProjectB</artifactId>
    <version>1.5-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Project A</name>
    ...
    <dependencies>
        ... 
        <dependency>
            <groupId>com.exemple.test</groupId>
            <artifactId>ProjectC</artifactId>
        </dependency>
        ...
    </dependencies>
    ...

</project>

Project C依赖于其他jar,并使用maven-shade-plugin插件。

项目C

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.exemple.test</groupId>
    <artifactId>ProjectC</artifactId>
    <version>1.5-SNAPSHOT</version>

    <name>ProjectC</name>


    <dependencies>
        ...
        <dependency>
            <groupId>test</groupId>
            <artifactId>anotherjar</artifactId>
            <version>1.5-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>test</groupId>
            <artifactId>anotherjar2</artifactId>
            <version>1.5-SNAPSHOT</version>
        </dependency>
        ...
    </dependencies>

   ...
    <build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-ssh</artifactId>
                <version>2.9</version>
            </extension>
        </extensions>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <excludes>
                                ...
                                <exclude>javax.servlet:jsp-api:jar:*</exclude>
                                <exclude>jboss:jbossall-client:jar:*</exclude>
                                ...
                                </excludes>
                            </artifactSet>
                            <filters> 
                                <filter>
                                <artifact>*:*</artifact>
                                    <excludes>
                                        <!--<exclude>**/*.sql</exclude>-->
                                        <exclude>**/*.sh</exclude>
                                        <exclude>**/*.bat</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
    </build>

</project>

在阴影插件中,我们找到了一个排除文件类型* .sql。

实际上,我只想在Project B中获得* .sql文件,而在Project A中则没有。

在Project B或Project A中是否可以做到这一点?

thx

0 个答案:

没有答案