Skip to content

Commit 2a72cc8

Browse files
committed
[MPMD-399] Incorrect warning: The project X does not seem to be compiled. PMD results might be inaccurate.
Update also FAQ about aggregate and type resolution- Co-authored-by: Andreas Dangel <adangel@apache.org> This closes #154
1 parent 71c807b commit 2a72cc8

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public abstract class AbstractPmdReport extends AbstractMavenReport {
140140
private File[] excludeRoots;
141141

142142
/**
143-
* Run PMD on the tests.
143+
* Run PMD on the tests as well.
144144
*
145145
* @since 2.2
146146
*/
@@ -152,7 +152,8 @@ public abstract class AbstractPmdReport extends AbstractMavenReport {
152152
*
153153
* @since 2.2
154154
* @deprecated since 3.15.0 Use the goals <code>pmd:aggregate-pmd</code> and <code>pmd:aggregate-cpd</code>
155-
* instead.
155+
* instead. See <a href="https://maven.apache.org/plugins/maven-pmd-plugin/faq.html#typeresolution_aggregate">FAQ:
156+
* Why do I get sometimes false positive and/or false negative violations?</a> for an explanation.
156157
*/
157158
@Parameter(property = "aggregate", defaultValue = "false")
158159
@Deprecated

src/main/java/org/apache/maven/plugins/pmd/PmdReport.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -513,23 +513,11 @@ private String determineAuxClasspath() throws MavenReportException {
513513
resolvedArtifact.getArtifact().getFile().toString());
514514
}
515515

516-
List<String> projectClasspath = includeTests
517-
? localProject.getTestClasspathElements()
518-
: localProject.getCompileClasspathElements();
519-
520-
// Add the project's target folder first
521-
classpath.addAll(projectClasspath);
522-
if (!localProject.isExecutionRoot()) {
523-
for (String path : projectClasspath) {
524-
File pathFile = new File(path);
525-
String[] children = pathFile.list();
526-
527-
if (!pathFile.exists() || (children != null && children.length == 0)) {
528-
getLog().warn("The project " + localProject.getArtifactId()
529-
+ " does not seem to be compiled. PMD results might be inaccurate.");
530-
}
531-
}
532-
}
516+
// Add the project's classes first
517+
classpath.addAll(
518+
includeTests
519+
? localProject.getTestClasspathElements()
520+
: localProject.getCompileClasspathElements());
533521
}
534522

535523
// Add the dependencies as last entries

src/site/fml/faq.fml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,24 @@ under the License.
101101
</faq>
102102
<faq id="typeresolution aggregate">
103103
<question>
104-
What does the warning "The project xyz does not seem to be compiled. PMD results might be inaccurate." mean?
104+
Why do I get sometimes false positive and/or false negative violations?
105105
</question>
106106
<answer>
107107
<p>
108108
In order to improve PMD's results, type resolution should be used. It is enabled by default
109109
(property <a href="pmd-mojo.html#typeResolution">typeResolution</a>) and helps to avoid false positive
110-
findings by matching the exact types of method parameters or variables.
110+
or false negative findings by matching the exact types of method parameters or variables.
111111
</p>
112112
<p>
113-
However, this requires that the project is built first, so that not only the project's dependencies
113+
However, this requires that the project is built first so that not only the project's dependencies
114114
can be used for type resolution, but also the project's classes as well.
115115
</p>
116116
<p>
117117
When using the property <a href="pmd-mojo.html#aggregate">aggregate</a>, this is problematic: With
118118
aggregate=true, PMD is executed at the root of a multi-module project <em>before the individual
119119
modules are built</em>. Then the types of the individual projects are not available, which might lead to
120-
false positive findings e.g. for the rule "UnusedPrivateMethod".
121-
If this might be the case, then the warning "The project xyz does not seem
122-
to be compiled. PMD results might be inaccurate" is issued.
120+
false positive findings e.g. for the rule "UnusedPrivateMethod". That's why this property has
121+
been deprecated.
123122
</p>
124123
<p>
125124
In order to use type resolution and aggregate together, maven needs to be execute in two passes:
@@ -135,4 +134,4 @@ under the License.
135134
</answer>
136135
</faq>
137136
</part>
138-
</faqs>
137+
</faqs>

0 commit comments

Comments
 (0)