【问题标题】:Skip git-code-format-maven-plugin from cosium during mvn install在 mvn 安装期间从 cosium 跳过 git-code-format-maven-plugin
【发布时间】:2021-12-07 13:16:43
【问题描述】:

我有一个项目使用 com.cosium.code 中的 git-code-format-maven-plugin 将代码格式化为预提交挂钩。我正在设置一个构建管道来安装这个项目,并且运行机器没有安装 git。

所以插件抛出异常

无法在项目 chat-srv 上执行目标 com.cosium.code:git-code-format-maven-plugin:3.1:install-hooks(默认):必须调用 setGitDir 或 setWorkTree 之一。 -> [帮助 1]

我正在执行的命令是mvn -f /app/pom.xml clean install

是否可以在 mvn 安装期间跳过代码格式化并仅对 git 提交启用它?或者是否可以在管道构建期间跳过使用插件?

pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
        </plugin>
        <plugin>
            <groupId>com.cosium.code</groupId>
            <artifactId>git-code-format-maven-plugin</artifactId>
            <version>3.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>install-hooks</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <googleJavaFormatOptions>
                    <aosp>true</aosp>
                </googleJavaFormatOptions>
            </configuration>
        </plugin>
    </plugins>
</build>

【问题讨论】:

    标签: maven maven-plugin code-formatting


    【解决方案1】:

    您可以使用属性 {} 跳过插件。在构建时使用属性并将其设置为 true。

    <properties>
            <skipFormatCode>false</skipFormatCode>
        </properties>    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <groupId>com.cosium.code</groupId>
                <artifactId>git-code-format-maven-plugin</artifactId>
                <version>3.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>install-hooks</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <skip>${skipFormatCode}</skip>
                    <googleJavaFormatOptions>
                        <aosp>true</aosp>
                    </googleJavaFormatOptions>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    当你想跳过插件运行时使用

    mvn clean install -DskipFormatCode=true

    【讨论】:

      猜你喜欢
      • 2021-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多