【问题标题】:Maven: plugin to fail a build if a string is foundMaven:如果找到字符串,则插件会导致构建失败
【发布时间】:2011-05-13 14:30:39
【问题描述】:

在开发过程中,我习惯于将不应该在生产中的代码包装在“TODEL”标签内。例如:

//TODEL - START

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

//TODEL - END 

如果我不小心签入了包含“TODEL”的文件,是否有一个 maven 插件会导致 jenkins 中的构建失败?

【问题讨论】:

  • 您确定不想为您的版本控制系统编写触发器,以防止您首先签入代码吗?
  • 如果你使用的是 eclipse,你可以在 Checkstyle 插件中设置一个规则来标记它。

标签: java maven maven-plugin


【解决方案1】:

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

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-checkstyle-plugin</artifactId>
   <configuration>
       <configLocation>my-checkstyle.xml</configLocation>
   </configuration>
</plugin>

配置属性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>

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

【讨论】:

  • 也许我会使用 PMD 而不是 Checkstyle,但除此之外:+1
猜你喜欢
  • 1970-01-01
  • 2011-05-25
  • 2021-04-02
  • 1970-01-01
  • 1970-01-01
  • 2017-03-23
  • 1970-01-01
  • 2015-09-04
  • 1970-01-01
相关资源
最近更新 更多