There are several dependencies in the project. However, two of them are not used in runtime:

<dependency> <groupId>org.jetbrains</groupId> <artifactId>annotations</artifactId> <version>${annotations.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>LATEST</version> <scope>test</scope> </dependency> 

Dependencies lie in the / lib folder next to the .jar.

It is necessary to exclude these two and related dependencies from the final distribution. Tried to do through <excludeArtifactIds>junit,annotations</excludeArtifactIds> However, related dependencies are not thus excluded. Tell me how to eliminate the main dependencies and associated with them without explicit reference to the latter.

pom.xml - section <plugins> :

  <!--region COMPILER--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>${plugin.compiler.version}</version> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> </configuration> </plugin> <!--endregion COMPILER--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>${plugin.jar.version}</version> <configuration> <outputDirectory>${distrib.directory}</outputDirectory> <excludes> <exclude>dataConfigs/**</exclude> <exclude>excelConfigs/**</exclude> <exclude>excelTemplates/**</exclude> <exclude>genToolsConfigs/**</exclude> </excludes> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>com.oaks.adnMaker.Main</mainClass> </manifest> <manifestEntries> <Class-Path>conf/</Class-Path> </manifestEntries> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>${plugin.resources.version}</version> <executions> <execution> <id>copy-resources</id> <phase>prepare-package</phase> <goals> <goal>copy-resources</goal> </goals> <!-- копируем файлы ресурсов в ${distrib.directory} --> <configuration> <outputDirectory>${distrib.directory}/conf</outputDirectory> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> <includes> <include>configuration/**</include> <include>dataConfigs/**</include> <include>excelConfigs/**</include> <include>excelTemplates/**</include> <include>genToolsConfigs/**</include> </includes> <filtering>false</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>${plugin.dependency.version}</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${distrib.directory}/lib</outputDirectory> <!--<excludeArtifactIds>junit,annotations</excludeArtifactIds>--> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> <plugin> <groupId>com.zenjava</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>${plugin.javafx.version}</version> <configuration> <mainClass>com.oaks.adnMaker.Main</mainClass> <vendor>oak_ic</vendor> </configuration> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version> <configuration> <descriptors> <descriptor>src/main/assembly/zip.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <!-- this is used for inheritance merges --> <phase>package</phase> <!-- append to the packaging phase. --> <goals> <goal>single</goal> <!-- goals == mojos --> </goals> </execution> </executions> </plugin> 
  • and how is the final distribution going? is it jar war - Mikhail Vaysman
  • @MikhailVaysman jar + separate folders with .jar dependencies and xml-configs - I. Perevoz

2 answers 2

Adding <includeScope>compile</includeScope> to the plugin configuration should solve the problem. Well, clearly indicate the scope of the first dependency. For example:

 <dependency> <groupId>org.jetbrains</groupId> <artifactId>annotations</artifactId> <version>${annotations.version}</version> <scope>provided</scope> </dependency> 

    For each dependency in Maven there is a scope parameter. The scope may be as follows:

    • compile
    • provided
    • runtime
    • test
    • system
    • import (Maven 2.0.9 or later)

    If you specify provided , then these dependencies and transitive dependencies will not be included in the resulting artifact.

    • Here is a snag. For junit'a scope = test explicitly specified, while the library is still added. I understand that the problem is in the config of the plugin. - I. Perevoz
    • can you add a minimal pom.xml to experiment? - Mikhail Vaysman
    • Added the <plugins> section to the question - I. Perevoz