Jakob
Jakob

Reputation: 151

The maven-assembly-plugin is ignored?

I have a question about the maven-assembly-plugin. When I run "install" on maven, it seems as if the assembly-plugin is not being used. The finalName is ignored and all dependencies are not compiled into the .jar. Is the problem in my 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>

    <groupId>removedgroupid</groupId>
    <artifactId>removedname</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                    <finalName>removedfinalname</finalName>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>jakarta.mail</artifactId>
            <version>1.6.4</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.6</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
            <version>2.5.2</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

</project>

I also wonder if my current Java version properties that I have set will be taken into account if the assembly plugin would work or if I then have to set this in the maven-compiler-plugin.

Upvotes: 0

Views: 1484

Answers (2)

majurageerthan
majurageerthan

Reputation: 2319

Try like this, (You missed executions)

<build>
   <plugins>
      <plugin>
         <artifactId>maven-assembly-plugin</artifactId>
         <configuration>
            <archive>
               <manifest>    
                  <addClasspath>true</addClasspath>
                  <mainClass>MainClass</mainClass>
               </manifest>
            </archive>
            <descriptorRefs>
               <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
         </configuration>
         <executions>
            <execution>
               <id>make-my-jar-with-dependencies</id>
               <phase>package</phase>
               <goals>
                  <goal>single</goal>
               </goals>
            </execution>
         </executions>
      </plugin>

   </plugins>
</build>

Note: Using this mvn clean install will make two jar

  1. Jar without dependencies
  2. Jar with dependencies

jar with dependencies contains name "jar-with-dependencies.jar" as mentioned in <descriptorRef>

Upvotes: 2

khmarbaise
khmarbaise

Reputation: 97527

The maven-assembly-plugin is not bound to the life cycle by default. This means you need to do that by yourself via the following:

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]
</project>

You are simply missing the part executions in your pom file. Afterwards you could simply do mvn clean package

Upvotes: 3

Related Questions