Maven:在处理多个配置文件时使用通用/共享插件

Sti*_*ens 10 maven-2

我有一个使用多个配置文件的项目.每个配置文件使用以下插件:

  • Maven的编译器插件
  • Maven的资源 - 插件
  • Maven的antrun-插件
  • Maven的万无一失,插件
  • Maven的战争插件

然而,以粗体标记的那个是唯一的插件,其中配置文件之间存在差异(将使用antrun插件复制不同的配置文件).所有配置文件的其他4个插件配置完全相同.

现在的问题是:是否有一些方法可以将这些常见插件只包含一次,但默认情况下仍然会将它们用于所有配置文件?

就像是:

<shared><plugin1><plugin2>...</shared>
<profile><plugin3></profile>
<profile><plugin3></profile>
...

谢谢,
Stijn

Rom*_*las 13

如果所有配置文件都使用了插件,只需在<build>部件中定义它:

<project>
...
    <build>
        <plugins>
             Your shared plugins go here...
        </plugins>

    <profiles>
        Definition of profiles...
    </profiles>
</project>
Run Code Online (Sandbox Code Playgroud)

这样,您只需在profiles块中定义antrun插件.


Pét*_*rök 6

只需在您的build部分中包含常见插件:

<build>
    <plugins>
        <plugin>
            <groupId>...</groupId>
            <artifactId>plugin1</artifactId>
        </plugin>
        ...
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

然后在您的个人资料中添加特定插件:

<profiles>
    <profile>
        <id>...</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>...</groupId>
                    <artifactId>plugin3</artifactId>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

您还可以通过以下方式在不同的配置文件中以不同方式配置相同的插

<profiles>
    <profile>
        <id>profile1</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>...</groupId>
                    <artifactId>plugin1</artifactId>
                    <configuration>
                        <setting>value1</setting>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>profile2</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>...</groupId>
                    <artifactId>plugin1</artifactId>
                    <configuration>
                        <setting>value2</setting>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)