java-sdk icon indicating copy to clipboard operation
java-sdk copied to clipboard

Why checkstyle failed if I added test in mvn command?

Open skyao opened this issue 2 years ago • 3 comments

Expected Behavior

Following two mvn commands I expected them are equals, because install will reply on compile and test.

mvn clean install
mvn clean test install

Actual Behavior

mvn clean install command will succeed, but mvn clean test install will fail:

mvn clean test install
......
[WARNING] target/generated-sources/io/dapr/v1/CommonProtos.java:[8272,62] (whitespace) OperatorWrap: '+' should be on a new line.
[WARNING] target/generated-sources/io/dapr/v1/CommonProtos.java:[8273,7] (indentation) Indentation: 'array initialization' child has incorrect indentation level 6, expected level should be one of the following: 8, 10.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] dapr-sdk-parent 1.11.0-SNAPSHOT .................... SUCCESS [  1.130 s]
[INFO] dapr-sdk-autogen 1.11.0-SNAPSHOT ................... FAILURE [ 14.571 s]
[INFO] dapr-sdk 1.11.0-SNAPSHOT ........................... SKIPPED
[INFO] dapr-sdk-actors 1.11.0-SNAPSHOT .................... SKIPPED
[INFO] dapr-sdk-workflows 0.11.0-SNAPSHOT ................. SKIPPED
[INFO] dapr-sdk-springboot 1.11.0-SNAPSHOT ................ SKIPPED
[INFO] dapr-sdk-examples 1.11.0-SNAPSHOT .................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  15.920 s
[INFO] Finished at: 2023-12-14T08:05:21Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check (validate) on project dapr-sdk-autogen: You have 18455 Checkstyle violations. -> [Help 1]

I even checked the code in end of 2022 year. This issue reappeared.

The root cause is that maven checkstyle plugin will check the generated code and then failed for violations for command "mvn clean test install". But if the command is "mvn clean install", maven checkstyle plugin won't check generated code.

Steps to Reproduce the Problem

  1. clone java-sdk repo and checkout to master branch
  2. run mvn clean test install

skyao avatar Dec 14 '23 08:12 skyao

I tried to find why the github action is always green without this issue, in the `.github/workflow/build.xml', I found that the script executed the mvn command of clean / compile / test / install one by one:

    - name: Clean up files
      run: ./mvnw clean -B
    - name: Build sdk
      run: ./mvnw compile -B -q
    - name: Unit tests
      run: ./mvnw -B test -q
    - name: Codecov
      uses: codecov/[email protected]
    - name: Install jars
      run: ./mvnw install -q -B -DskipTests

I tried to run these commands in local, they all passed without violations. And from the log I found that the log of checkstyle plugin:

and in the second step ./mvnw compile -B ( I removed -q to see more log):

[INFO] --- maven-checkstyle-plugin:3.1.1:check (validate) @ dapr-sdk-autogen ---
[INFO] Starting audit...
Audit done.
[INFO] You have 0 Checkstyle violations.

The checkstyle plugin executed in mvn compile but no violations found. It means that at this moment, checkstyle plugin didn't check the generated source code.

The github action didn't run test and install at the same time, so it's lucky and succeed.

skyao avatar Dec 14 '23 09:12 skyao

The checkstyle plugin will be executed in mvn compile phase, so let's change to compile and test, not install and test.

I executed following three commands one by one and no error found:

mvn clean
mvn compile
mvn test

While I executed compile and test together:

mvn clean
mvn compile test
......
......
[WARNING] target/generated-sources/io/dapr/v1/CommonProtos.java:[8272,7] (indentation) Indentation: 'array initialization' child has incorrect indentation level 6, expected level should be one of the following: 8, 10.
[WARNING] target/generated-sources/io/dapr/v1/CommonProtos.java:[8272,62] (whitespace) OperatorWrap: '+' should be on a new line.
[WARNING] target/generated-sources/io/dapr/v1/CommonProtos.java:[8273,7] (indentation) Indentation: 'array initialization' child has incorrect indentation level 6, expected level should be one of the following: 8, 10.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] dapr-sdk-parent 1.11.0-SNAPSHOT .................... SUCCESS [  0.943 s]
[INFO] dapr-sdk-autogen 1.11.0-SNAPSHOT ................... FAILURE [ 27.961 s]
[INFO] dapr-sdk 1.11.0-SNAPSHOT ........................... SKIPPED
[INFO] dapr-sdk-actors 1.11.0-SNAPSHOT .................... SKIPPED
[INFO] dapr-sdk-workflows 0.11.0-SNAPSHOT ................. SKIPPED
[INFO] dapr-sdk-springboot 1.11.0-SNAPSHOT ................ SKIPPED
[INFO] dapr-sdk-examples 1.11.0-SNAPSHOT .................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  29.130 s
[INFO] Finished at: 2023-12-14T09:12:45Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check (validate) on project dapr-sdk-autogen: You have 18455 Checkstyle violations. -> [Help 1]

skyao avatar Dec 14 '23 09:12 skyao

The checkstyle plugin will behave inconsistently:

  • Executing "mvn compile" alone, the checkstyle plugin will only check the source directory
  • Executing "mvn compile test" together, the checkstyle plugin will check the source directory, the test source directory, and the generated source directory.

To fix it, set the sourceDirectories of checkstyle configuration to only sourceDirectory:

          <sourceDirectories>
            <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
          </sourceDirectories>

skyao avatar Dec 14 '23 16:12 skyao

@artursouza this looks solved too.. can we close it?

salaboy avatar Dec 04 '24 16:12 salaboy

Closing per the above comment. Feel free to re-open if this is still an issue

cicoyle avatar Mar 27 '25 16:03 cicoyle