4
votes

I ran into such a situation, when packaging a project using maven, I'd like both the source package and the binary package, and they have the same manifest.mf file. Then I have to write the same entry in both plugin configuration of maven-source-plugin and maven-jar-plugin, like this:

        <plugins>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Artifiact>${project.name}</Artifiact>
                            <Version>${project.version}</Version>
                            <Vendor>${project.organization.name}</Vendor>
                            <Built-By>Shiva Wu</Built-By>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                        <manifestEntries>
                            <Artifiact>${project.name}</Artifiact>
                            <Version>${project.version}</Version>
                            <Vendor>${project.organization.name}</Vendor>
                            <Built-By>Shiva Wu</Built-By>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins> 
    


It's really not convenient to modify both of them while changing settings. Is there a better way to resolve this?

Thanks:)

1

1 Answers

0
votes

There is no better way to handle it than what you are doing.

A couple extra things though. You can stick these configurations into a reuseable "corporate" or "standard" parent POM within the plugin management section and then you won't have to specify them again in any other pom. See here for details:

Best way to share portions of a Maven pom.xml across unrelated projects?

The other thing I notice is that your personal name should be substituted with a variable that should be set from within your settings.xml file. This will help increase build portability.