Skip to content

Commit 9aa0fc0

Browse files
lars-shmichael-o
authored andcommitted
[MDEP-714] Add analyze parameter "ignoreUnusedRuntime"
This closes #123
1 parent cf6fdeb commit 9aa0fc0

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals = clean ${project.groupId}:${project.artifactId}:${project.version}:analyze
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.its.dependency</groupId>
27+
<artifactId>test</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
30+
<name>Test</name>
31+
<description>
32+
Test dependency:analyze with ignoreUnusedRuntime
33+
</description>
34+
35+
<properties>
36+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
37+
</properties>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.apache.maven</groupId>
42+
<artifactId>maven-project</artifactId>
43+
<version>2.0.6</version>
44+
<scope>runtime</scope>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<pluginManagement>
50+
<plugins>
51+
<plugin>
52+
<artifactId>maven-dependency-plugin</artifactId>
53+
<configuration>
54+
<verbose>true</verbose>
55+
<failOnWarning>true</failOnWarning>
56+
<ignoreUnusedRuntime>true</ignoreUnusedRuntime>
57+
</configuration>
58+
</plugin>
59+
</plugins>
60+
</pluginManagement>
61+
</build>
62+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
public class Main
21+
{
22+
}

src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ public abstract class AbstractAnalyzeMojo
101101
@Parameter( property = "ignoreNonCompile", defaultValue = "false" )
102102
private boolean ignoreNonCompile;
103103

104+
/**
105+
* Ignore Runtime scope for unused dependency analysis.
106+
*/
107+
@Parameter( property = "ignoreUnusedRuntime", defaultValue = "false" )
108+
private boolean ignoreUnusedRuntime;
109+
104110
/**
105111
* Output the xml for the missing dependencies (used but not declared).
106112
*
@@ -324,6 +330,11 @@ private boolean checkDependencies()
324330
Set<Artifact> ignoredUsedUndeclared = new LinkedHashSet<>();
325331
Set<Artifact> ignoredUnusedDeclared = new LinkedHashSet<>();
326332

333+
if ( ignoreUnusedRuntime )
334+
{
335+
filterArtifactsByScope( unusedDeclared, Artifact.SCOPE_RUNTIME );
336+
}
337+
327338
ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclared, ignoredDependencies ) );
328339
ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclared, ignoredUsedUndeclaredDependencies ) );
329340

@@ -402,6 +413,18 @@ private boolean checkDependencies()
402413
return warning;
403414
}
404415

416+
private void filterArtifactsByScope( Set<Artifact> artifacts, String scope )
417+
{
418+
for ( Iterator<Artifact> iterator = artifacts.iterator(); iterator.hasNext(); )
419+
{
420+
Artifact artifact = iterator.next();
421+
if ( artifact.getScope().equals( scope ) )
422+
{
423+
iterator.remove();
424+
}
425+
}
426+
}
427+
405428
private void logArtifacts( Set<Artifact> artifacts, boolean warn )
406429
{
407430
if ( artifacts.isEmpty() )

0 commit comments

Comments
 (0)