Hide manifest entries with maven

When creating a jar file with maven, it will create a manifest file in META-INF / MANIFEST.MF. Currently its contents are:

Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Built-By: <my username> Created-By: Apache Maven 3.1.0 Build-Jdk: 1.8.0_5 

How can I hide manifest posts? In particular, I would like to hide the "Built-By:" entry because I see no reason why my username should be indicated in the bank.

+12
source share
3 answers

The documentation for the maven-achiver plugin seems pretty clear that you cannot delete properties, just set them empty, as described in Alex Chernyshev's answer . To get more control over MANIFEST.MF, you should not use the maven-archiver plugin.

One alternative would be to use the maven antrun plugin and the Ant Jar task to create a Jar.

In pom.xml:

 <project> ... <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <executions> <execution> <phase>package</phase> <configuration> <target> <jar destfile="test.jar" basedir="."> <include name="build"/> <manifest> <attribute name="Manifest-Version:" value="1.0"/> </manifest> </jar> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ... </project> 

Another option is to invoke the Jar tool directly using the Maven exec plugin .

I do not like to recommend antrun, since I consider this a dirty hack, but it seems that the maven-archiver does not meet your requirements. It might be worthwhile to raise a function request for maven-archiver.

EDIT: 2014-10-06 lifted Jira MSHARED-362

EDIT: 2018-06-18: updated link to Jira and Maven Exec plugin

EDIT: 2019-01-14: the fix is ​​for maven-archiver-3.4.0

+7
source

Add

 <addDefaultImplementationEntries>false</addDefaultImplementationEntries> 

to the maven-jar-plugin configuration section in your pom.xml to completely remove the default properties:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addDefaultImplementationEntries>false</addDefaultImplementationEntries> </manifest> </archive> </configuration> </plugin> 

to configure it (delete only username):

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifestEntries> <Built-By></Built-By> </manifestEntries> </archive> </configuration> </plugin> 
+5
source

Set user.name to an empty string.

mvn -Duser.name="" package

Or, if you are using Eclipse, add -Duser.name="" to the arguments of the Maven startup configuration virtual machine (Run β†’ Run as β†’ Build Maven ... β†’ JRE tab β†’ enter -Duser.name="" in the VM arguments field) .

0
source

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


All Articles