Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: assembly-plugin is not run at all

I am pretty new to Maven, tried to learn a couple of times before and figured I was better off without Maven. Now, (un)fortunately I have to use Maven in a project I'd like to contribute to. My problem at this point is regarding the packaging. I'd like to produce a self-contained (aka "fat") jar with all dependencies included, and a colleague who's played around with Maven helped me out with the pom file.

I have checked his pom files, as well as samples here on SO. The xml looks legit but the plugin is not run at all. Note that I get no errors, everything goes fine except I get no "fatjar". Any ideas what might be the cause of this problem?

Below is the relevant portion of the pom.xml. I have seen contradicting code samples with regards to positioning of <configuration> and <executions> tags, tried pretty much every variation I have found, still no joy.

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.3</version>
  <executions>
    <execution>
        <id>make-jar-with-dependencies</id> <!-- this is used for inheritance merges -->
        <phase>package</phase> <!-- bind to the packaging phase -->
        <goals>
            <goal>single</goal>
        </goals>
    </execution>
  </executions>
  <configuration>
    <finalName>ProjectName</finalName>
    <appendAssemblyId>true</appendAssemblyId>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    <archive>
      <manifest>
        <mainClass>org.mydomain.ProjectName</mainClass>
        <addClasspath>true</addClasspath>
      </manifest>
    </archive>
  </configuration>
</plugin>

Edit_1 the console output from mvn clean package as asked by @khmarbaise

[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ myproject ---
[INFO] Deleting /home/user/workspace/project/target
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ myproject ---
[debug] execute contextualize
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 41 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ myproject ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 292 source files to /home/user/workspace/project/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ myproject ---
[debug] execute contextualize
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/user/workspace/project/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ myproject ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ myproject ---
[INFO] No tests to run.
[INFO] Surefire report directory: /home/user/workspace/project/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ myproject ---
[INFO] Building jar: /home/user/workspace/project/target/myproject-2.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.210s
[INFO] Finished at: Thu Jun 07 11:45:14 CEST 2012
[INFO] Final Memory: 18M/184M
[INFO] ------------------------------------------------------------------------
like image 451
posdef Avatar asked Jun 07 '12 09:06

posdef


People also ask

What is goal single in Maven?

This goal is suitable either for binding to the lifecycle or calling directly from the command line (provided all required files are available before the build starts, or are produced by another goal specified before this one on the command line).

What is Maven Shade plugin?

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.


1 Answers

I would recommend to create a uberjar by using the maven-shade-plugin, cause it's intention is exactly that purpose. You can do that with the maven-assembly-plugin as well.

So after taking a look into your pom i understand the problem. First you defined the maven-assembly-plugin in the pluginManagement block which will NOT execute a plugin furthermore you have defined the maven-assembly-plugin as a dependency separately which is superfluous. Which means simply remove the following from your pom:

<dependency>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-assembly-plugin</artifactId>
   <version>2.3</version>
   <type>maven-plugin</type>
</dependency>

You should define the maven-assembler-plugin like this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            ...all your configuration here..
        </plugin>
    </plugins>
</build>

Furthermore i've seen many repository definition which should be handled by repository manager instead. About the repositories in your pom i can recommend reading the sonatype information furthermore you should think about some else will use the project behind a proxy etc. than he has to change you pom to get i working or can't use it cause you defined repositories in your pom he can't reach.

like image 133
khmarbaise Avatar answered Oct 05 '22 06:10

khmarbaise