1

I have a multi modules maven project

abc
  +-- child1
  +-- child2
  +-- child3
  +-- distribution

So my final jar will look like

META-INF/
META-INF/MANIFEST.MF
com/
com/myapp/
com/myapp/service/
com/myapp/service/
com/myapp/service/ServiceFactory.class
com/myapp/service/Counter.class
META-INF/maven/
META-INF/maven/com.myapp/
META-INF/maven/com.myapp/abc/
META-INF/maven/com.myapp/abc/pom.xml
META-INF/maven/com.myapp/abc/pom.properties

child1 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>
            <parent>
                <artifactId>abc</artifactId>
                <groupId>com.myapp</groupId>
                <version>1.0-SNAPSHOT</version>
            </parent>

            <packaging>jar</packaging>

            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                    <version>1.7.25</version>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.7.0</version>
                        <configuration>
                            <source>${maven.compiler.source}</source>
                            <target>${maven.compiler.target}</target>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </project>

abc 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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
     <artifactId>abc</artifactId>
     <groupId>com.myapp</groupId>
     <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>child1</module>
        <module>distribution</module>
    </modules>
</project>

At the moment the slf4j is inside the final jar and I would like to create a jar which contains child1 and child2, but not contains slf4j which is dependency of child1. Can someone point me to the right direction?

user293655
  • 508
  • 1
  • 6
  • 23
  • you can specify the `scope` of the dependency.. see: https://stackoverflow.com/questions/26975818/what-is-scope-under-dependency-in-pom-xml-for – Kenneth Clark Dec 06 '17 at 06:03
  • Or, if you use `maven-assembly-plugin`, you can try [custom assembly](https://maven.apache.org/guides/mini/guide-assemblies.html) – Kirill Simonov Dec 06 '17 at 06:27

0 Answers0