简体   繁体   中英

Including excluded jar package with Maven Assembly Plugin

have a pom.xml

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

<!-- other parts -->

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-common</artifactId>
        <version>2.0.0-cdh4.2.1</version>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-log4j12</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass></mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
                <execution>
                    <id>index</id>
                    <phase>package</phase>
                    <configuration>
                        <descriptors>
                            <descriptor>src/main/assembly/index.xml</descriptor>
                        </descriptors>
                    </configuration>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

the "index.xml" assembly file

<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd">
<id>index</id>
<formats>
    <format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>

<dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <unpack>false</unpack>
        <includes>
            <include>org.slf4j:slf4j-log4j12</include>
        </includes>
    </dependencySet>
    </dependencySets>

<files>
    <file>
        <source>${project.build.directory}/${artifactId}-${version}-jar-with-dependencies.jar</source>
        <fileMode>0644</fileMode>
        <outputDirectory>/</outputDirectory>
        <destName>${artifactId}-${version}-index.jar</destName>
    </file>
</files>
</assembly>

the jar generated using maven predefined assembly descriptors "jar-with-dependencies" is to be used in Storm, must excludes slf4j-log4j12 package, Storm also include it. but have a "indexer" class in it is used independently, it need slf4j-log4j12 package to log, when running "maven install", got:

[WARNING] The following patterns were never triggered in this artifact inclusion filter: o 'org.slf4j:slf4j-log4j12'

how to fix this problem in the "index.xml" assembly file?

i think the only way is define different dependency strategy by different maven profile. Proposed reference hadoop maven config.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM