I have a project that is using git-code-format-maven-plugin from com.cosium.code to format code as a pre-commit hook. I am setting up a build pipeline to install this project and the runner machines do not have git installed.
So the plugin is throwing exception
Failed to execute goal com.cosium.code:git-code-format-maven-plugin:3.1:install-hooks (default) on project chat-srv: One of setGitDir or setWorkTree must be called. -> [Help 1]
Command I am executing is mvn -f /app/pom.xml clean install
Is it possible to skip the code foramtting during the mvn install and enable it only for git commits? Or isit possible to skip using the plugin during the pipeline builds?
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>
You can skip a plugin by using the attribute {}. Use a property and set it to true when you are building.
<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>
When you want to skip the plugin run using
mvn clean install -DskipFormatCode=true