开发者

How to remove duplicate content from pom.xml for Maven?

开发者 https://www.devze.com 2023-01-22 17:53 出处:网络
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 entr

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>
                <configur开发者_如何学Goation>
                    <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:)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消