Maven:如果找到字符串,插件将失败

Thi*_*Roy 4 java maven-plugin maven

在开发过程中,我习惯在"TODEL"标签内包装不应该生产的代码.例如:

//TODEL - START

//used to test the crashing behavior
String s = null;
int i = s.length;

//TODEL - END 
Run Code Online (Sandbox Code Playgroud)

如果我不小心检查包含"TODEL"的文件,是否有maven插件可以使jenkins中的构建失败?

sse*_*ano 5

你可以做的一件事是使用maven checkstyle plugin.您可以设置规则,如果不符合这些规则,则使构建失败.

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-checkstyle-plugin</artifactId>
   <configuration>
       <configLocation>my-checkstyle.xml</configLocation>
   </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

配置属性maven.checkstyle.fail.on.violation.

然后mvn checkstyle:check.或者通过添加到插件配置将其配置为在您选择的阶段(编译或进程资源)中执行:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-checkstyle-plugin</artifactId>
   <executions>
       <execution>
           <id>TODEL</id>
           <configuration>
               <configLocation>my-checkstyle.xml</configLocation>
           </configuration>
           <goals>
               <goal>check</goal>
           </goals>
           <phase>validate</phase>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

更多信息:http://maven.apache.org/plugins/maven-checkstyle-plugin