Unable to disable empty JAR generation (maven-jar-plugin)

Sometimes my Talend Open Studio components have resources, but not Java sources (they are purely metadata components). I need to disable JAR file generation in this case.

I configured maven-jar-plugin this way:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <forceCreation>false</forceCreation> <skipIfEmpty>true</skipIfEmpty> <useDefaultManifestFile>false</useDefaultManifestFile> </configuration> </plugin> 

but I still get the $ {project.name} .jar file with pom.properties, pom.cml, a manifest, and an empty App.class file containing only "class {}"

Although I can disable all maven elements using this:

 <archive> <addMavenDescriptor>false</addMavenDescriptor> </archive> 

I am still getting a JAR with a manifest file inside it

Are there any configuration options that I configured incorrectly?

+2
source share
3 answers

I found the solution myself, even if it is only a workaround. I delete the JAR using the antrun removal task if the / src / main / java directory does not exist:

 <!-- remove the empty JAR if not needed --> <if> <not><available file="${basedir}/src/main/java" type="dir" /></not> <then> <delete file="${project.build.directory}/${project.name}-${project.version}.jar"/> </then> </if> 

this task requires antcontrib to work correctly, and cc does not work if you plan to make releases using maven (but this is normal for metadata-only components such as Talend Open Studio plugins)

+1
source

The most efficient way to disable can creation is to configure maven-jar-plugin as follows:

 <plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>2.3.1</version> <executions> <execution> <id>default-jar</id> <phase>none</phase> </execution> </executions> </plugin> </plugins> 

It will put the default jar creation in the none phase, it will never run.

+5
source

You can specify maven-jar-plugin to not generate META-INF / maven / * / pom. files as described in the Maven Archiver Reference .

Alternatively, you can use the skipIfEmpty option.

The following code combines both of these objects (only so that they are ready for copying):

 ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <skipIfEmpty>true</skipIfEmpty> <archive> <addMavenDescriptor>false</addMavenDescriptor> </archive> ... 

This works fine, but when you do mvn install , it fails due to the lack of a project artifact. A similar problem will probably be with mvn deploy and with the release, but I have not tested them.

However, if you can live with antrun delete, the skipIfEmpty property skipIfEmpty probably work well for you and a little more elegantly. At least he does not introduce a new performance and its dependencies, etc.

+1
source

Source: https://habr.com/ru/post/973264/


All Articles