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

Version 18 does not reformat code but version 16 does #74

Closed
jknight opened this issue Nov 2, 2022 · 20 comments
Closed

Version 18 does not reformat code but version 16 does #74

jknight opened this issue Nov 2, 2022 · 20 comments

Comments

@jknight
Copy link

jknight commented Nov 2, 2022

Version 18 does not reformat my code whereas version 16 does.

Here's my configuration that works (following README.md)

      <plugin>
        <groupId>com.hubspot.maven.plugins</groupId>
        <artifactId>prettier-maven-plugin</artifactId>
        <version>0.16</version>
        <configuration>
          <prettierJavaVersion>1.5.0</prettierJavaVersion>
          <ignoreConfigFile>true</ignoreConfigFile>
          <ignoreEditorConfig>true</ignoreEditorConfig>
        </configuration>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>${plugin.prettier.goal}</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

with this config, mvn verify reformats my code as expected ✅

However, if I change to v18:

[...]
 <version>0.18</version>
    <configuration>
      <prettierJavaVersion>1.6.2</prettierJavaVersion>
[...]

mvn verify does not reformat my code. I don't see any complaints - it just doesn't do anything.
mvn prettier:print-args seems happy enough (?)

I see from the PR Notes

users will need to migrate to a proper prettier-java release before upgrading to this version

Is there some extra manual step I need to perform to use v18 ?

@jhaber
Copy link
Member

jhaber commented Nov 2, 2022

Can you paste the full output from the plugin when formatting doesn't work? Curious to see if there's anything that jumps out at me

@jknight
Copy link
Author

jknight commented Nov 2, 2022

v18 config:

pom.xml

<properties>
  [...]
  <plugin.prettier.goal>write</plugin.prettier.goal>
  [...]
</properties>
[...]
  <build>
    <plugins>
      <plugin>
        <groupId>com.hubspot.maven.plugins</groupId>
        <artifactId>prettier-maven-plugin</artifactId>
        <version>0.18</version>
        <configuration>
          <prettierJavaVersion>1.6.2</prettierJavaVersion>
          <printWidth>120</printWidth>
          <tabWidth>4</tabWidth>
          <useTabs>false</useTabs>
          <ignoreConfigFile>true</ignoreConfigFile>
          <ignoreEditorConfig>true</ignoreEditorConfig>
        </configuration>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>${plugin.prettier.goal}</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]

FIle with formatting issues:

apps/myapp/src/main/java/com/myorg/etc/MyApplication.java (curly braces on their own line + bad indenting):

[...]
public class MyApplication implements Application
{
private final Logger log = Logger.getLogger(MyApplication.class);
private KafkaProducer kafkaProducer;
[...]

Run mvn -DskipTests verify.
Java file formatting unchanged (same as above).

Maven output was:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] parent                                                             [pom]
[INFO] MyOrg My Utilities                                              [jar]
[INFO] MyOrg My Gateway                                                [jar]
[INFO] MyOrg My Topic Manager                                          [jar]
[INFO] 
[INFO] -----------------------< com.myorg.my:parent >-----------------------
[INFO] Building parent 1.0.0-SNAPSHOT                                     [1/4]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- prettier-maven-plugin:0.18:write (default) @ parent ---
[INFO] No input directories found
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:prepare-agent (default) @ parent ---
[INFO] argLine set to -javaagent:/home/jknight/.m2/repository/org/jacoco/org.jacoco.agent/0.8.8/org.jacoco.agent-0.8.8-runtime.jar=destfile=/home/jknight/my-gateway/target/jacoco.exec
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:generate-code (default) @ parent ---
[INFO] Type of the artifact is POM, skipping build goal
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:generate-code-tests (default) @ parent ---
[INFO] Type of the artifact is POM, skipping build goal
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ parent ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:build (default) @ parent ---
[INFO] Type of the artifact is POM, skipping build goal
[INFO] 
[INFO] --------------------< com.myorg.utils:my-utils >---------------------
[INFO] Building MyOrg My Utilities 1.0.0-SNAPSHOT                      [2/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- prettier-maven-plugin:0.18:write (default) @ my-utils ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:prepare-agent (default) @ my-utils ---
[INFO] argLine set to -javaagent:/home/jknight/.m2/repository/org/jacoco/org.jacoco.agent/0.8.8/org.jacoco.agent-0.8.8-runtime.jar=destfile=/home/jknight/my-gateway/libs/my-utils/target/jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-utils ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jknight/my-gateway/libs/my-utils/src/main/resources
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:generate-code (default) @ my-utils ---
[INFO] 
[INFO] --- flatten-maven-plugin:1.2.5:flatten (flatten) @ my-utils ---
[INFO] Generating flattened POM of project com.myorg.utils:my-utils:jar:1.0.0-SNAPSHOT...
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ my-utils ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:generate-code-tests (default) @ my-utils ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-utils ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jknight/my-gateway/libs/my-utils/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ my-utils ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M7:test (default-test) @ my-utils ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ my-utils ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ my-utils ---
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:build (default) @ my-utils ---
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 1696ms
[INFO] 
[INFO] ---------------------< com.myorg.my:mygateway >---------------------
[INFO] Building MyOrg My Gateway 1.0.0-SNAPSHOT                        [3/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- prettier-maven-plugin:0.18:write (default) @ mygateway ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:prepare-agent (default) @ mygateway ---
[INFO] argLine set to -javaagent:/home/jknight/.m2/repository/org/jacoco/org.jacoco.agent/0.8.8/org.jacoco.agent-0.8.8-runtime.jar=destfile=/home/jknight/my-gateway/apps/my-gateway/target/jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mygateway ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:generate-code (default) @ mygateway ---
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ mygateway ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:generate-code-tests (default) @ mygateway ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mygateway ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jknight/my-gateway/apps/my-gateway/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ mygateway ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M7:test (default-test) @ mygateway ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ mygateway ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mygateway ---
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:build (default) @ mygateway ---
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 1483ms
[INFO] 
[INFO] -----------------< com.myorg.my:my-topic-manager >------------------
[INFO] Building MyOrg My Topic Manager 1.0.0-SNAPSHOT                  [4/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- prettier-maven-plugin:0.18:write (default) @ my-topic-manager ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:prepare-agent (default) @ my-topic-manager ---
[INFO] argLine set to -javaagent:/home/jknight/.m2/repository/org/jacoco/org.jacoco.agent/0.8.8/org.jacoco.agent-0.8.8-runtime.jar=destfile=/home/jknight/my-gateway/apps/my-topic-manager/target/jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-topic-manager ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jknight/my-gateway/apps/my-topic-manager/src/main/resources
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:generate-code (default) @ my-topic-manager ---
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ my-topic-manager ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:generate-code-tests (default) @ my-topic-manager ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-topic-manager ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jknight/my-gateway/apps/my-topic-manager/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ my-topic-manager ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M7:test (default-test) @ my-topic-manager ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ my-topic-manager ---
[INFO] Loading execution data file /home/jknight/my-gateway/apps/my-topic-manager/target/jacoco.exec
[INFO] Analyzed bundle 'MyOrg My Topic Manager' with 2 classes
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ my-topic-manager ---
[INFO] 
[INFO] --- quarkus-maven-plugin:2.10.4.Final:build (default) @ my-topic-manager ---
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 1306ms
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for parent 1.0.0-SNAPSHOT:
[INFO] 
[INFO] parent ............................................. SUCCESS [  0.379 s]
[INFO] MyOrg My Utilities .............................. SUCCESS [  3.431 s]
[INFO] MyOrg My Gateway ................................ SUCCESS [  2.241 s]
[INFO] MyOrg My Topic Manager .......................... SUCCESS [  2.020 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.755 s
[INFO] Finished at: 2022-11-02T18:37:44Z
[INFO] ------------------------------------------------------------------------

Notes:

  • folder path is somewhat non-standard (Nx structure) of apps/
  • node --version: 16.14.0
  • I don't have prettier installed globally or in this project:
     pnpm prettier
     ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  not found: prettier
    
    Maybe I need to yarn/pnpm install prettier ?
    [EDIT: pnpm install prettier didn't do it]

@gaetanmaisse
Copy link

@jknight are you using MacOS? I'm asking as I face the same issue locally but everything is fine on CI.

Also, I created a simple repository that reproduces the issue: https://github.com/gaetanmaisse/prettier-maven-plugin-issue
It just contains 2 simple maven projects with a Main class containing a single wrongly indented method.

As I explain in the readme of my repo, everything is ok when using version 0.17 but nothing happens locally when running 0.18. A few clues after my first investigation:

  • With 0.18 + sudo mode -> Everything is ok
  • Using GitPod to run on a Linux machine -> Everything is ok (whatever the version)
  • When running with -X maven option I have the following:
...
[DEBUG] Determined os: MAC_X64
[DEBUG] Downloading node from url: https://nodejs.org/dist/v16.13.2/node-v16.13.2-darwin-x64.tar.gz
[DEBUG] Downloaded node to: /Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-9379861215282969351.tmp
[DEBUG] Extracted node to: /Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-8885610596549673583
[DEBUG] Moved node to: /Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64
[DEBUG] Running npm install command: [/Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/bin/node, /Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/lib/node_modules/npm/bin/npm-cli.js, install, prettier-plugin-java@1.6.1]

changed 2 packages, and audited 1664 packages in 12s

243 packages are looking for funding
  run `npm fund` for details

23 vulnerabilities (22 high, 1 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
[DEBUG] Downloaded prettier-java to: /Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1
[DEBUG] Running prettier with args: /Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/bin/node /Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1/node_modules/prettier/bin-prettier.js --plugin=/Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1/node_modules/prettier-plugin-java --color --check src/main/java/**/*.java src/test/java/**/*.java
[DEBUG] Prettier exit code: 1

We can notice the [DEBUG] Prettier exit code: 1, also if I check the content of /Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1 then it's empty.

Same command in sudo mode:

...
[DEBUG] Determined os: MAC_X64
[DEBUG] Reusing cached node at: /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64
[DEBUG] Reusing cached prettier-java at: /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1
[DEBUG] Running prettier with args: /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/bin/node /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1/node_modules/prettier/bin-prettier.js --plugin=/var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1/node_modules/prettier-plugin-java --color --check src/main/java/**/*.java src/test/java/**/*.java
[ERROR] Incorrectly formatted file: src/main/java/org/example/Main.java
[INFO] No files matching the pattern were found: "src/test/java/**/*.java".
[DEBUG] Prettier exit code: 2

And /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1 do contain some files.

Let me know if I can help with further investigation!

@jhaber
Copy link
Member

jhaber commented Nov 9, 2022

Thanks to both of you for the detailed write-up. @gaetanmaisse I tried your reproducer but everything seemed to behave as expected for me (16" M1 Macbook, macOS 12.6). I ran mvn prettier:check, and got the expected error. Then I ran mvn prettier:write and it reformatted the code. Then I ran mvn prettier:check again and the build succeeded. Here's the full output I got:
https://gist.github.com/jhaber/bc3b09149b1140c8da3537da0eb35e19

@jhaber
Copy link
Member

jhaber commented Nov 9, 2022

Are y'all on macOS Ventura? I wonder if there might be some sort of permission change going on? Especially since you mentioned it works with sudo. When you build with -X (without sudo), it prints the command that it's going to run. What happens if you run this command manually?

/Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/bin/node /Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1/node_modules/prettier/bin-prettier.js --plugin=/Users/gmaisse/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1/node_modules/prettier-plugin-java --color --check src/main/java/**/*.java src/test/java/**/*.java

@jknight
Copy link
Author

jknight commented Nov 9, 2022

Using @gaetanmaisse repo, I get the same results he does - 17 ✅ 18 ❌

  • MacOS Ventura 13.0 Beta (22A5365d)
  • node --version = v16.14.0
  • npm --version = 8.3.1
  • java --version = openjdk 17.0.3 2022-04-19
  • prettier not installed globally: pnpm pretier:  ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND  No package.json (or package.yaml, or package.json5) was found

I also see the exit 1 @gaetanmaisse reported and can confirm v18 works with sudo.

Full results here:

  1. mvn prettier:check v17 - detects formatting issue: ✅
  2. mvn prettier:check v18 - fails to detect formatting issue ❌
  3. mvn prettier:check -X v18 - fails to detect formatting issue and we see exit 1
  4. sudo mvn prettier:check v18 - - detects formatting issue: ✅

Conclusion:
image

@jknight
Copy link
Author

jknight commented Nov 9, 2022

Something with the download + permissions?

# Pre-clear the prettier dir to force new download ...
rm -rf /Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin

# Run, non-sudo ...
mvn prettier:check
[...]
[DEBUG] Determined os: MAC_X64
[DEBUG] Downloading node from url: https://nodejs.org/dist/v16.13.2/node-v16.13.2-darwin-x64.tar.gz
[DEBUG] Downloaded node to: /Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-1021355396566564595.tmp
[DEBUG] Extracted node to: /Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-14205196155308076570
[DEBUG] Moved node to: /Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64
[DEBUG] Running npm install command: [/Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/bin/node, /Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/lib/node_modules/npm/bin/npm-cli.js, install, prettier-plugin-java@1.6.1]

up to date, audited 10 packages in 2s

found 0 vulnerabilities
[DEBUG] Downloaded prettier-java to: /Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1
[DEBUG] Running prettier with args: /Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/bin/node /Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1/node_modules/prettier/bin-prettier.js --plugin=/Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1/node_modules/prettier-plugin-java --color --check src/main/java/**/*.java
[DEBUG] Prettier exit code: 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.882 s
[INFO] Finished at: 2022-11-09T13:11:10Z
[INFO] ------------------------------------------------------------------------

^^ says it "Downloaded prettier-java to: /Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1" -- let's check:

> ls -alh /Users/jknight/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1
total 0
drwxr-xr-x  2 jknight  staff    64B Nov  9 13:02 .
drwxr-xr-x  9 jknight  staff   288B Nov  9 13:02 ..

Empty ?

But doing the same with sudo does download it to var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1:

# Remove it to force a new download ...
sudo rm -rf  /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/
# Run prettier -X as sudo ...
sudo mvn:prettier -X 
[...]
[DEBUG] Determined os: MAC_X64
[DEBUG] Downloading node from url: https://nodejs.org/dist/v16.13.2/node-v16.13.2-darwin-x64.tar.gz
[DEBUG] Downloaded node to: /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-11761585108782352696.tmp
[DEBUG] Extracted node to: /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-17376624761748570133
[DEBUG] Moved node to: /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64
[DEBUG] Running npm install command: [/var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/bin/node, /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/node-v16.13.2-darwin-x64/lib/node_modules/npm/bin/npm-cli.js, install, prettier-plugin-java@1.6.1]

Did it download in sudo mode ? yes:

> sudo ls -alh /var/root/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-1.6.1
total 16
drwxr-xr-x   5 root  wheel   160B Nov  9 13:06 .
drwxr-xr-x   9 root  wheel   288B Nov  9 13:06 ..
drwxr-xr-x  10 root  wheel   320B Nov  9 13:06 node_modules
-rw-r--r--   1 root  wheel   4.0K Nov  9 13:06 package-lock.json
-rw-r--r--   1 root  wheel    65B Nov  9 13:06 package.json

@jtkiesel
Copy link
Contributor

jtkiesel commented Feb 3, 2023

We are noticing the same issue, and have reproduced it on both macOS Ventura and Monterey. For Monterey, we noticed that macOS versions 12.6.2 and 12.6.3 both experience the issue, but 12.6.1 does not (I assume @jhaber was running 12.6.1?)

@jhaber
Copy link
Member

jhaber commented Feb 3, 2023

I'm now on Ventura 13.2 and still haven't had any luck reproducing the issue. Our company has >1,000 engineers on a mix of MacOS versions and no one has seen this issue either 🤔 I wonder if there's maybe a specific MacOS security setting that triggers the issue?

@jtkiesel
Copy link
Contributor

jtkiesel commented Feb 3, 2023

Strange... My team of 4 is using company-managed MacBook Pros, so perhaps they have enabled such a security setting.

@ChristianAnke
Copy link

ChristianAnke commented Feb 16, 2023

Hello,
i encoundered the same issue on linux kubuntu 22.10. I ran into the problem with the Prettier exit code: 1 .

When i execute the command manually i got:

node /home/christian-anke/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-2.0.0/node_modules/prettier/bin-prettier.js --plugin=/home/christian-anke/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-2.0.0/node_modules/prettier-plugin-java --color --print-width 120 --tab-width 2 --use-tabs true --no-config --no-editorconfig --check src/main/java/**/*.java src/test/java/**/*.java src/integration-test/java/**/*.java
node:internal/modules/cjs/loader:1042
  throw err;
  ^

Error: Cannot find module '/home/christian-anke/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-2.0.0/node_modules/prettier/bin-prettier.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
    at Module._load (node:internal/modules/cjs/loader:885:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v19.3.0

I noticed that the module was installed to ~/node_modules so i copied it like so:

cp -a ~/node_modules /home/christian-anke/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-2.0.0

After that the check works.

Maybe the module was just installed to the wrong place?

Furthermore i see another issue: That the exit code is 1 should lead to an build error. It is not helpful that the plugin is not failing when it was not able to perform the work. I would thing is just found nothing to complain about. Instead it was doing nothing.

@ChristianAnke
Copy link

ChristianAnke commented Feb 16, 2023

Cleaning the following files/dirs helped to solve it:

  • ~/node_modules/
  • ~/.npm
  • ~/package-lock.json
  • ~/package.json <-- that was the last one where it started working when was removed

content of ~/package.json

{
  "dependencies": {
    "prettier-plugin-java": "^2.0.0"
  }
}

It seemt to be that npm is installing it to the gloabl node_modules when ~/package.json exists with content {} and the module is mentioned.

@ChristianAnke
Copy link

ChristianAnke commented Feb 16, 2023

Maybe 84af10d already is doing the trick?

Yes it does, tested it against 0.19-SNAPSHOT

When can we expect a release?

@jhaber
Copy link
Member

jhaber commented Feb 17, 2023

Ah the plugin version we use internally tracks the master branch, so we've already picked up that commit which could explain why we can't reproduce this issue. I can cut a new release and see if it the new version fixes this issue for people

@ChristianAnke
Copy link

Please keep in mind that the directory ~/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.18/prettier-java-* has to be removed, otherwise the install will not be triggered again.

@ChristianAnke
Copy link

ChristianAnke commented Feb 17, 2023

It turns out in another instance of that issue we had to remove all the following:

  • ~/node_modules/
  • ~/.npm
  • ~/package-lock.json
  • ~/package.json
    Maybe ~/package-lock.json and ~/package.json is enough, but i can not validate anymore.

@jhaber
Copy link
Member

jhaber commented Feb 21, 2023

I just released version 0.19, if some people reporting this issue can try upgrading and see if it fixes this issue I would appreciate it

@gaetanmaisse
Copy link

@jhaber just tested version 0.19 on the simple repo I used to highlight the issue and everything is back to normal 🎉 🍾

@jeffkni
Copy link

jeffkni commented Feb 22, 2023

Confirmed working in v19 - let's close it ! 🥳 THANK YOU @jhaber !

@jhaber
Copy link
Member

jhaber commented Feb 22, 2023

Awesome, sorry it took so long to track down the issue

@jhaber jhaber closed this as completed Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants