13

When building a jar file with maven, it will create a manifest file in META-INF/MANIFEST.MF. Its contents currently 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 entries? In particular I would like to hide the "Built-By:" entry because I don't see any reason why a jar should include my username.

  • I have the same question even though it is not limited to the Built-By in particular and I have not found any solution. I am putting a bounty on this question, because I have also found exactly what you have found in the comments to the only answer this question has. – DanielBarbarian Sep 29 '14 at 09:13

4 Answers4

9

The maven-achiver plugin documentation seems pretty clear that you cannot remove properties, only set them to blank as described in Alex Chernyshev's answer. In order to get more control over the 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 build the 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 alternative is calling the Jar tool directly using the Maven exec plugin.

I don't like recommending antrun, as I think it's a dirty hack, but it seems that maven-archiver does not meet your requirements. It might be worth raising a feature request for maven-archiver.

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

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

EDIT: 2019-01-14: Fix targeted for maven-archiver-3.4.0

Michael-O
  • 18,123
  • 6
  • 55
  • 121
Richard Neish
  • 8,414
  • 4
  • 39
  • 69
  • How about use of [maven shade plugin](https://maven.apache.org/plugins/maven-shade-plugin/)? – user11153 Oct 01 '14 at 12:08
  • I don't see how to use the maven shade plugin to accomplish what the question is asking. If you know how to do that, please submit the details as an answer, I would be interested in seeing it. – Richard Neish Oct 01 '14 at 12:59
  • `The maven-achiver plugin documentation seems pretty clear that you cannot remove properties`. I don't agree, in the documentation page you linked to it says nothing about removing properties. It does describe what is default, but that does not necessarily mean you can't remove them. However that does not mean your answer is not right though and it really does seem to be so. – DanielBarbarian Oct 03 '14 at 11:42
  • Well, the documentation doesn't say anything about removing properties, only adding them. That seems pretty clear as indicating that you cannot remove properties using the maven-archiver plugin. That was what I meant. – Richard Neish Oct 03 '14 at 11:50
  • As I have encountered many incomplete documentations before I never take it for granted. In this case I have not seen anything on how to solve this issue and the only way would be to get the plugin changed. Since I have no doubt that you are right about your answer, the bounty is yours. – DanielBarbarian Oct 06 '14 at 05:52
  • 1
    @RichardNeish I've added a patch into the MSHARED-362 Jira ticket you mentioned in your answer. Hope it will be accepted. – Rostislav Krasny Oct 30 '18 at 16:10
  • 1
    I am working on all of them, soon you'll be able to drop all of them except `Manifest-Version`. – Michael-O Jan 29 '19 at 16:51
  • Thanks @Michael-O and others - I've been following the discussion on MSHARED-362 and MSHARED-787, great work. – Richard Neish Jan 30 '19 at 09:39
6

Add

<addDefaultImplementationEntries>false</addDefaultImplementationEntries>

to configration section of maven-jar-plugin in your pom.xml to completely remove 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 customize it (remove just username):

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestEntries>
                        <Built-By></Built-By>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
Alex Chernyshev
  • 1,719
  • 9
  • 11
  • 2
    The second solution works (the entry is still in the manifest but entry however). The first solution doesn't, the default entries are still in the manifest for me. According to [the documentation](https://maven.apache.org/shared/maven-archiver/examples/manifest.html), addDefaultImplementationEntries is just for the Implementation-* entries. –  Aug 02 '14 at 19:17
  • Arrh! My fault! use this to completely remove generated properties: false http://stackoverflow.com/questions/13218313/unable-to-disable-generation-of-empy-jar-maven-jar-plugin – Alex Chernyshev Aug 02 '14 at 19:22
  • As far as I can see, that affects only the pom.xml that is included in the jar by default, but not the MANIFEST.MF. –  Aug 02 '14 at 19:25
  • Then this is double fault) Just create your own empty file and use it as: src/custom-manifest.txt – Alex Chernyshev Aug 02 '14 at 19:30
  • 1
    That just does the same as specifying entries in ``, the custom manifest gets merged with the default manifest but the entries don't go away. –  Aug 02 '14 at 19:38
3

Set user.name variable to empty string.

mvn -Duser.name="" package

Or if you are using Eclipse add -Duser.name="" to VM arguments of Maven run configuration (Run -> Run As -> Maven build... -> JRE tab -> enter -Duser.name="" in VM arguments field).

user1257
  • 622
  • 1
  • 8
  • 13
0

This removes all default entries from manifest

<addDefaultEntries>false</addDefaultEntries>

Example

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <addDefaultEntries>false</addDefaultEntries>
            </manifest>
        </archive>
    </configuration>
</plugin>
n90p
  • 1