Skip to content

Commit

Permalink
Merge pull request mojohaus#69 from sebthom/issue-52-ignore-optional-…
Browse files Browse the repository at this point in the history
…deps

Add option ignoreOptionals to EnforceByteCodeVersion. Fixes mojohaus#52
  • Loading branch information
batmat authored Jan 17, 2019
2 parents 61ec7cd + 852d6a1 commit a48e0cf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = enforcer:enforce install
invoker.buildResult = success
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>enforce-bytecode-version-ignore-optional-dependencies</artifactId>
<version>1.0-SNAPSHOT</version>
<description>GitHub Issue #52 - ignoring optional dependencies </description>
<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@enforcerPluginVersion@</version>
<dependencies>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.2</maxJdkVersion>
<ignoredScopes>
<!-- exclude junit/hamcrest -->
<ignoredScope>test</ignoredScope>
</ignoredScopes>
<ignoreOptionals>true</ignoreOptionals>
</enforceBytecodeVersion>
</rules>
</configuration>
<executions>
<execution>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- this artifact contains classes targeting JDK 1.3 or newer -->
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ static String renderVersion( int major, int minor )
*/
private String[] ignoredScopes;

/**
* Ignore all dependencies which have {@code &lt;optional&gt;true&lt;/optional&gt;}.
* @since 1.2
*/
private boolean ignoreOptionals = false;

private List<IgnorableDependency> ignorableDependencies = new ArrayList<IgnorableDependency>();

@Override
Expand Down Expand Up @@ -399,7 +405,7 @@ public void setSearchTransitive( boolean theSearchTransitive )
*/
private Set<Artifact> filterArtifacts( Set<Artifact> dependencies )
{
if ( includes == null && excludes == null && ignoredScopes == null )
if ( includes == null && excludes == null && ignoredScopes == null && ignoreOptionals == false )
{
return dependencies;
}
Expand All @@ -421,6 +427,10 @@ private Set<Artifact> filterArtifacts( Set<Artifact> dependencies )
{
continue;
}
if ( ignoreOptionals && artifact.isOptional() )
{
continue;
}
if ( filter.include( artifact ) )
{
result.add( artifact );
Expand Down
2 changes: 2 additions & 0 deletions src/site/apt/enforceBytecodeVersion.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Enforce Bytecode Version

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

* ignoreOptionals - a boolean, if <<<true>>> all dependencies which have <<<<optional>true</optional>>>> are ignored.

[]

Note
Expand Down

0 comments on commit a48e0cf

Please sign in to comment.