Skip to content

Commit a48e0cf

Browse files
authored
Merge pull request mojohaus#69 from sebthom/issue-52-ignore-optional-deps
Add option ignoreOptionals to EnforceByteCodeVersion. Fixes mojohaus#52
2 parents 61ec7cd + 852d6a1 commit a48e0cf

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = enforcer:enforce install
2+
invoker.buildResult = success
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>test</groupId>
6+
<artifactId>enforce-bytecode-version-ignore-optional-dependencies</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<description>GitHub Issue #52 - ignoring optional dependencies </description>
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<artifactId>maven-enforcer-plugin</artifactId>
13+
<version>@enforcerPluginVersion@</version>
14+
<dependencies>
15+
<dependency>
16+
<groupId>@project.groupId@</groupId>
17+
<artifactId>@project.artifactId@</artifactId>
18+
<version>@project.version@</version>
19+
</dependency>
20+
</dependencies>
21+
<configuration>
22+
<rules>
23+
<enforceBytecodeVersion>
24+
<maxJdkVersion>1.2</maxJdkVersion>
25+
<ignoredScopes>
26+
<!-- exclude junit/hamcrest -->
27+
<ignoredScope>test</ignoredScope>
28+
</ignoredScopes>
29+
<ignoreOptionals>true</ignoreOptionals>
30+
</enforceBytecodeVersion>
31+
</rules>
32+
</configuration>
33+
<executions>
34+
<execution>
35+
<phase>compile</phase>
36+
</execution>
37+
</executions>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
<dependencies>
42+
<dependency>
43+
<groupId>junit</groupId>
44+
<artifactId>junit</artifactId>
45+
<version>4.11</version>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<!-- this artifact contains classes targeting JDK 1.3 or newer -->
50+
<groupId>javax.transaction</groupId>
51+
<artifactId>jta</artifactId>
52+
<version>1.1</version>
53+
<optional>true</optional>
54+
</dependency>
55+
</dependencies>
56+
</project>

src/main/java/org/apache/maven/plugins/enforcer/EnforceBytecodeVersion.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ static String renderVersion( int major, int minor )
150150
*/
151151
private String[] ignoredScopes;
152152

153+
/**
154+
* Ignore all dependencies which have {@code &lt;optional&gt;true&lt;/optional&gt;}.
155+
* @since 1.2
156+
*/
157+
private boolean ignoreOptionals = false;
158+
153159
private List<IgnorableDependency> ignorableDependencies = new ArrayList<IgnorableDependency>();
154160

155161
@Override
@@ -399,7 +405,7 @@ public void setSearchTransitive( boolean theSearchTransitive )
399405
*/
400406
private Set<Artifact> filterArtifacts( Set<Artifact> dependencies )
401407
{
402-
if ( includes == null && excludes == null && ignoredScopes == null )
408+
if ( includes == null && excludes == null && ignoredScopes == null && ignoreOptionals == false )
403409
{
404410
return dependencies;
405411
}
@@ -421,6 +427,10 @@ private Set<Artifact> filterArtifacts( Set<Artifact> dependencies )
421427
{
422428
continue;
423429
}
430+
if ( ignoreOptionals && artifact.isOptional() )
431+
{
432+
continue;
433+
}
424434
if ( filter.include( artifact ) )
425435
{
426436
result.add( artifact );

src/site/apt/enforceBytecodeVersion.apt.vm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Enforce Bytecode Version
4141

4242
* ignoredScopes - a list of scopes (e.g. test, provided) to ignore when scanning artifacts
4343

44+
* ignoreOptionals - a boolean, if <<<true>>> all dependencies which have <<<<optional>true</optional>>>> are ignored.
45+
4446
[]
4547

4648
Note

0 commit comments

Comments
 (0)