Skip to content

Commit

Permalink
allow ignoring test only deps with scope compile, add them to json re…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
cgo-disy committed Jan 17, 2022
1 parent 33ebafd commit 5ee0ea7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ under the License.
</parent>

<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.1-disy-1</version>
<version>3.2.1-disy-2</version>
<packaging>maven-plugin</packaging>

<name>Apache Maven Dependency Plugin</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ public abstract class AbstractAnalyzeMojo
@Parameter
private String[] ignoredUnusedDeclaredDependencies = new String[0];

@Parameter
private String[] ignoredCompileScopedUsedOnlyInTestsDependencies = new String[0];

/**
* List of project packaging that will be ignored.
* <br/>
Expand Down Expand Up @@ -359,6 +362,8 @@ private boolean checkDependencies()
ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredDependencies ) );
ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredUnusedDeclaredDependencies ) );

filterDependencies( testArtifactsWithNonTestScope, ignoredCompileScopedUsedOnlyInTestsDependencies );

boolean reported = false;
boolean warning = false;

Expand Down Expand Up @@ -420,7 +425,7 @@ private boolean checkDependencies()

if ( outputJSON )
{
writeDependencyJSON( usedUndeclared, unusedDeclared );
writeDependencyJSON( usedUndeclared, unusedDeclared, testArtifactsWithNonTestScope );
}

if ( scriptableOutput )
Expand Down Expand Up @@ -526,9 +531,13 @@ private String joinArtifacts( List<Artifact> artifacts )
return sb.toString();
}

private void writeDependencyJSON( Set<Artifact> usedUndeclared, Set<Artifact> unusedDeclared )
private void writeDependencyJSON(
Set<Artifact> usedUndeclared,
Set<Artifact> unusedDeclared,
Set<Artifact> testArtifactsWithNonTestScope
)
{
if ( !usedUndeclared.isEmpty() || !unusedDeclared.isEmpty() )
if ( !usedUndeclared.isEmpty() || !unusedDeclared.isEmpty() || !testArtifactsWithNonTestScope.isEmpty() )
{
StringBuilder buf = new StringBuilder();

Expand All @@ -550,6 +559,16 @@ private void writeDependencyJSON( Set<Artifact> usedUndeclared, Set<Artifact> un
buf.append( joinArtifacts( new ArrayList<>( unusedDeclared ) ) );
buf.append( "]" );
}
if ( !testArtifactsWithNonTestScope.isEmpty() )
{
if ( !usedUndeclared.isEmpty() || !unusedDeclared.isEmpty() )
{
buf.append( ", " );
}
buf.append( "testOnlyWithNonTestScope: [" );
buf.append( joinArtifacts( new ArrayList<>( testArtifactsWithNonTestScope ) ) );
buf.append( "]" );
}
buf.append( "}" );
getLog().warn( buf.toString() );
}
Expand Down

0 comments on commit 5ee0ea7

Please sign in to comment.