What is the best way to avoid maven-jar?
Solution 1
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.
Solution 2
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>
Solution 3
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>
Solution 4
What happens if you declare this?
<packaging>pom</packaging>
Even if it does what you're looking for, be careful. I'm not sure if there could be negative side effects -- such as other maven projects that depend on your jar not being able to locate it.
Solution 5
Using maven 3.3.9, the following worked for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
<configuration>
<finalName>unwanted</finalName>
<classifier>unwanted</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
So in case of the maven-jar-plugin, I bound it to a non-existent phase. For the maven-install-plugin, I used the "skip" configuration parameter. The documentation about it says: "Set this to true to bypass artifact installation. Use this for artifacts that does not need to be installed in the local repository."
Comments
-
unj2 almost 2 years
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
- I tried to remove the
-
Devanshu Mevada about 14 yearsAre you sure? I just tried that and I still see
[INFO] [jar:jar {execution: default-jar}]
. -
Artem about 14 yearsI've made the source plugin go away this way, but I've never had to get rid of the jar plugin, so I am NOT sure.
-
Brett Porter about 14 yearsthis would require you rebind all the goals, as it'll turn off compilation, testing, etc.
-
Admin almost 13 yearsThanks, this is great. I did the same <phase>never</phase> with the maven-war-plugin and was able to shut that bad boy down. :-)
-
JBert over 10 yearsI was confused where you got the
default-jar
execution id from. It took me some time to notice that Maven prints that id during each execution:[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ myproj ---
In this case it isdefault-install
, but it's similar for every other plugin. Thanks for the sample though. -
ZachOfAllTrades over 10 yearsdoes not work (at least not for me inside IDE using Maven 3.0.4
-
Matthew Wise almost 10 yearsAnd the same for the maven-install-plugin to prevent it complaining that no artifact was produced.
-
Matthew Wise almost 10 years"no way to unbind a plugin bound to a phase" - isn't that what
<phase />
does in the answer above? -
Sinisha Mihajlovski about 9 yearsThis produces invalid xml. My Intelij complains about the xml validity
-
user2163960 almost 9 yearsThe configuration mentioned above is wrong - I don't see any <skip> option on the configuration. There is, however, this option: <skipIfEmpty>true</skipIfEmpty> Which will work for some use cases - where you have a module that doesn't have any classes of its own - so you don't want the jar - but you do want to leave the packaging set to 'jar' (because setting it to pom confuses Eclipse and Netbeans when you try to launch code that is on the dependency path from this module) maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html
-
hennr almost 8 yearsThis is a wrong answer. The skip switch does someting different. Documention says: "Set this to true to bypass unit tests entirely. Its use is NOT RECOMMENDED, but quite convenient on occasion."
-
Jose Duarte about 6 yearsMore explicitly, the maven-install-plugin problem can be avoided with:
<plugin> <artifactId>maven-install-plugin</artifactId> <executions> <execution> <id>default-install</id> <phase>never</phase> </execution> </executions> </plugin>
-
Martin Höller about 6 yearsUse phase
none
to avoid the XML validation error. -
Steve Owens over 5 yearsThe above approach yields [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project **** : The packaging for this project did not assign a file to the build artifact -> [Help 1] [
-
Alexander Mills about 5 yearsis it really impossible to disable this with a command line switch?
-
Alexander Mills about 5 yearsThis worked, it looks like this plugin is used by default by mvn package even if it's not explicitly in the pom.xml file...I assume if you include it in pom.xml it overrides the default?
-
Alexander Mills about 5 yearsInstead of
</phase>
I used<phase>none</phase>
which seems a little more clean. -
Rosberg Linhares almost 3 yearsJust for information, this solution works, but not for the install phase.