Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why checkstyle failed if I added test in mvn command? #972

Open
skyao opened this issue Dec 14, 2023 · 3 comments
Open

Why checkstyle failed if I added test in mvn command? #972

skyao opened this issue Dec 14, 2023 · 3 comments
Labels
kind/bug Something isn't working

Comments

@skyao
Copy link
Member

skyao commented Dec 14, 2023

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 skyao added the kind/bug Something isn't working label Dec 14, 2023
@skyao skyao changed the title Why checkstyle failed if I add test in mvn command? Why checkstyle failed if I added test in mvn command? Dec 14, 2023
@skyao
Copy link
Member Author

skyao commented Dec 14, 2023

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
Copy link
Member Author

skyao commented Dec 14, 2023

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
Copy link
Member Author

skyao commented Dec 14, 2023

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant