You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "efegokdemir (via GitHub)" <gi...@apache.org> on 2026/09/24 08:26:47 UTC

[PR] Avoid generating Checkstyle files for empty projects [maven-checkstyle-plugin]

efegokdemir opened a new pull request, #712:
URL: https://github.com/apache/maven-checkstyle-plugin/pull/712

   ## Summary
   
   POM-only projects do not need Checkstyle analysis artifacts when no configured source or resource files match. This change skips the check goal before creating output, cache, configuration, or header files when there is nothing to process.
   
   ## Changes
   
   - Detect matching source, test-source, and enabled resource files before starting Checkstyle.
   - Add a regression test covering an empty project and asserting no Checkstyle artifacts are created.
   
   ## Testing
   
   - `mvn -Dspotless.check.skip=true -Dspotless.apply.skip=true -Dtest=CheckstyleViolationCheckMojoTest#testNoSourceDoesNotCreateOutputFiles test` — passed
   - `mvn -Dspotless.check.skip=true -Dspotless.apply.skip=true test` — passed (27 tests, 1 skipped)
   - `git diff --check` — passed
   - `mvn -Dspotless.check.skip=true -Dspotless.apply.skip=true -Prun-its verify` — interrupted after confirming the affected integration scenarios; remaining Invoker scenarios are blocked by Groovy's Java 27 class-file compatibility (`Unsupported class file major version 71`)
   
   Fixes #341
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Avoid generating Checkstyle files for empty projects [maven-checkstyle-plugin]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #712:
URL: https://github.com/apache/maven-checkstyle-plugin/pull/712#discussion_r4248063379


##########
src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojoTest.java:
##########
@@ -92,6 +95,19 @@ public void testNoOutputFile(CheckstyleViolationCheckMojo mojo) throws Exception
         mojo.execute();
     }
 
+    @InjectMojo(goal = "check", pom = "src/test/resources/plugin-configs/no-source-check-plugin-config.xml")
+    @Test
+    public void testNoSourceDoesNotCreateOutputFiles(CheckstyleViolationCheckMojo mojo) throws Exception {
+        project.setPackaging("pom");
+        mojo.execute();
+
+        File outputDirectory = new File("target/test-harness/checkstyle/no-source-check");
+        assertFalse(new File(outputDirectory, "checkstyle-cachefile").exists());
+        assertFalse(new File(outputDirectory, "checkstyle-checker.xml").exists());
+        assertFalse(new File(outputDirectory, "checkstyle-header.txt").exists());
+        assertFalse(new File(outputDirectory, "checkstyle-result.xml").exists());
+    }

Review Comment:
   This test hard-codes a relative path (`target/...`) and does not clean up any pre-existing outputs, which can make it flaky depending on the working directory and prior test runs. Prefer building the path from the test project's basedir (e.g., `project.getBasedir()`) and deleting the output directory (or at least the specific files) before `mojo.execute()`. Also consider asserting the output directory itself was not created if the intent is 'no artifacts at all'.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Avoid generating Checkstyle files for empty projects [maven-checkstyle-plugin]

Posted by "efegokdemir (via GitHub)" <gi...@apache.org>.
efegokdemir commented on code in PR #712:
URL: https://github.com/apache/maven-checkstyle-plugin/pull/712#discussion_r4249565902


##########
src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java:
##########
@@ -507,6 +507,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
             return;
         }
 
+        if (!skipExec && "pom".equalsIgnoreCase(project.getPackaging())) {
+            getLog().info("Not executing Checkstyle for a pom project.");

Review Comment:
   The skip message now uses debug level, and the focused and full unit suites pass (27 tests, 1 skipped).



##########
src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojoTest.java:
##########
@@ -92,6 +95,19 @@ public void testNoOutputFile(CheckstyleViolationCheckMojo mojo) throws Exception
         mojo.execute();
     }
 
+    @InjectMojo(goal = "check", pom = "src/test/resources/plugin-configs/no-source-check-plugin-config.xml")
+    @Test
+    public void testNoSourceDoesNotCreateOutputFiles(CheckstyleViolationCheckMojo mojo) throws Exception {
+        project.setPackaging("pom");
+        mojo.execute();
+
+        File outputDirectory = new File("target/test-harness/checkstyle/no-source-check");
+        assertFalse(new File(outputDirectory, "checkstyle-cachefile").exists());
+        assertFalse(new File(outputDirectory, "checkstyle-checker.xml").exists());
+        assertFalse(new File(outputDirectory, "checkstyle-header.txt").exists());
+        assertFalse(new File(outputDirectory, "checkstyle-result.xml").exists());
+    }

Review Comment:
   The test now uses an output path under the fixture’s basedir, removes stale output first and asserts that the directory remains absent. The full unit suite passed (27 tests, 1 skipped); the Invoker harness could not finish under local Java 27 because Groovy rejects class-file version 71.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Avoid generating Checkstyle files for empty projects [maven-checkstyle-plugin]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #712:
URL: https://github.com/apache/maven-checkstyle-plugin/pull/712#discussion_r4247920913


##########
src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java:
##########
@@ -507,6 +507,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
             return;
         }
 
+        if (!skipExec && "pom".equalsIgnoreCase(project.getPackaging())) {
+            getLog().info("Not executing Checkstyle for a pom project.");

Review Comment:
   debug at most



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org