Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to avoid maven-jar?

I am using a different plugin (ant4eclipse) to jar my files. What is the best way to avoid the maven-jar plugin from executing?

  • I tried to remove the <plugin>maven-jar-plugin</plugin>
  • I tried to <exclude> ** / * < / exclude>
  • I tried to <skip>true</skip>

None worked

like image 916
unj2 Avatar asked Feb 03 '10 00:02

unj2


3 Answers

In Maven 3.0.x (I tried 3.0.2) you can disable maven-jar-plugin by binding the default-jar execution to a nonexistent phase, as @bmargulies suggested. Unfortunately that doesn't work in 2.2.1, but you can prevent it from interfering with your own jar by setting an alternative <finalName> and <classifier> for the default-jar execution; it will still create a jar, but it will be set as a secondary artifact for the project and won't overwrite the one you've created. Here's an example that should work in both Maven 2 and Maven 3:

<project>   <modelVersion>4.0.0</modelVersion>    <groupId>test</groupId>   <artifactId>test</artifactId>   <version>0.1-SNAPSHOT</version>    <build>     <plugins>       <plugin>         <artifactId>maven-jar-plugin</artifactId>         <executions>           <execution>             <id>default-jar</id>             <phase>none</phase>             <configuration>               <finalName>unwanted</finalName>               <classifier>unwanted</classifier>             </configuration>           </execution>         </executions>       </plugin>     </plugins>   </build> </project> 

Once you've disabled maven-jar-plugin, maven-install-plugin may give you trouble too. In Maven 3 it can be disabled the same as maven-jar-plugin: bind default-install to a nonexistent phase. However, in Maven 2 maven-install-plugin requires that the target/classes directory exist, and it will install the dummy jar when there isn't a primary artifact present.

like image 105
peterj Avatar answered Oct 03 '22 06:10

peterj


This should do the trick - notice the use of <id>default-jar</id> and <phase/>.

  <build>     <plugins>       <plugin>         <groupId>org.apache.maven.plugins</groupId>         <artifactId>maven-jar-plugin</artifactId>         <version>2.4</version>         <executions>           <execution>             <id>default-jar</id>             <phase/>           </execution>         </executions>       </plugin>     </plugins>   </build> 
like image 43
redhot Avatar answered Oct 03 '22 07:10

redhot


In my case, I only wanted to disable the jar plugin because the jar was empty. You can use the skipIfEmpty option in the plugin configuration

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.0.2</version>
    <configuration>
        <skipIfEmpty>true</skipIfEmpty>
    </configuration>
</plugin>
like image 20
bheussler Avatar answered Oct 03 '22 06:10

bheussler