制作Maven插件可选吗?

时间:2018-02-03 15:29:21

标签: apache maven

如何制作maven插件可选,如果有人没有,他们的构建不会失败?在这个例子中,我试图让JSHint成为可选项,以便在你有权访问该插件时运行它。

2 个答案:

答案 0 :(得分:0)

您可以在项目build profile中声明POM并根据文件存在将其激活:

mvn ... -P jshint ...

但是,限制是存储库路径包含版本。

与版本无关,您可以在settings.xml

中默认激活配置文件
1Would you like Food or Drink? Enter either y for option one or n for the other.
1Would you like Hot food y/n?
Tomato Soup
Chicken salad
1Would you like a Fizzy drink? y/n?
Pepsi
Water

和其他人可以在命令行上激活它,以防:

Would you like Food or Drink? Enter either y for option one or n for the other.
    Would you like Hot food y/n?
        Tomato Soup
        Chicken Salad
   Would you like a Fizzy drink? y/n?
        Pepsi
        Water

答案 1 :(得分:0)

您需要创建具有唯一ID的其他配置文件

   <profiles>
    <profile>
        <id>no-optional-plugins</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <!-- active this profile to enable the docker-maven-plugin -->
    <id>docker</id>
    <activation>
        <activeByDefault>false</activeByDefault>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.26.0</version>
                <extensions>true</extensions>
                <configuration>
                    <verbose>true</verbose>
                    <images>
                        <image>
                            <name>${docker.image.prefix}/${project.parent.artifactId}/${project.artifactId}</name>
                            <build>
                                <from>java:8-jdk-alpine</from>
                                <entryPoint>
                                    <exec>
                                        <args>java</args>
                                        <args>-jar</args>
                                        <args>/maven/${project.artifactId}-${project.version}.jar</args>
                                    </exec>
                                </entryPoint>
                                <assembly>
                                    <descriptorRef>artifact</descriptorRef>
                                </assembly>
                            </build>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>build</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    </profile>
</profiles>

使用docker映像创建进行构建 mvn全新安装-P docker

在没有docker的情况下进行构建 mvn全新安装