简体   繁体   中英

How to confiugure maven-enforcer-plugin to exclude some rule in test scope?

How to confiugure maven-enforcer-plugin to exclude some rule in test scope?

I have such a configuration:

<executions>
  <execution>
    <id>enforce-bytecode-version</id>
    <goals>
      <goal>enforce</goal>
    </goals>
    <configuration>
      <rules>
        <enforceBytecodeVersion>
          <maxJdkVersion>1.7</maxJdkVersion>
        </enforceBytecodeVersion>
      </rules>
      <fail>true</fail>
    </configuration>
  </execution>
</executions>

But I would like to check JDK version only for regular code and not for test scope.

This can simply being done by using the appropriate configuration :

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.0.0-M1</version>
        <executions>
          <execution>
            <id>enforce-bytecode-version</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <enforceBytecodeVersion>
                  <maxJdkVersion>1.7</maxJdkVersion>
                  <ignoredScopes>
                     <ignoreScope>test</ignoreScope>
                   </ignoredScopes>
                </enforceBytecodeVersion>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>extra-enforcer-rules</artifactId>
            <version>1.0-beta-7</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

I also would recommend to use a more recent version of maven-enforcer-plugin .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM