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

Fix Maven Wrapper EOL issues #23

Merged
merged 2 commits into from
May 28, 2024

Conversation

mches
Copy link
Contributor

@mches mches commented Apr 29, 2024

I hit a snag trying Testcontainers Cloud Desktop for the first time with Java on Windows due to the line endings of the Maven Wrapper script on a fresh clone. On Windows, core.autocrlf defaults to true, but mvnw needs to have LF line endings and mvnw.cmd needs to have CRLF line endings, regardless of platform. Up until Maven Wrapper 3.3.1, it was also the case that .mvn/wrapper/maven-wrapper.properties needed to have LF line endings regardless of platform, in order to validate the distribution and wrapper SHA-256 sums on Windows. This PR fixes the all the issues at once by adding .gitattributes and upgrading Maven Wrapper to v3.3.2. Note that newer versions of Maven Wrapper don't even require the wrapper JAR or downloader source files.

This is my onboarding experience using Git Bash on Windows:

$ git clone https://github.com/AtomicJar/testcontainers-cloud-java-example
Cloning into 'testcontainers-cloud-java-example'...
remote: Enumerating objects: 154, done.
remote: Counting objects: 100% (60/60), done.
remote: Compressing objects: 100% (33/33), done.
Rremote: Total 154 (delta 37), reused 28 (delta 20), pack-reused 94
Receiving objects: 100% (154/154), 845.18 KiB | 4.59 MiB/s, done.
Resolving deltas: 100% (56/56), done.

$ cd testcontainers-cloud-java-example

$ make test
bash: make: command not found

$ ./mvnw test
Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain
Caused by: java.lang.ClassNotFoundException: org.apache.maven.wrapper.MavenWrapperMain

And here is how it worked out after adding .gitattributes and upgrading Maven Wrapper to v3.3.2:

$ ./mvnw test
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< cloud.testcontainers:java-example >------------------
[INFO] Building java-example 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ java-example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\dev\testcontainers-cloud-java-example\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ java-example ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ java-example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ java-example ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to E:\dev\testcontainers-cloud-java-example\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M7:test (default-test) @ java-example ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running cloud.testcontainers.example.TestcontainersCloudFirstTest
02:00:10.371 [main] INFO  org.testcontainers.images.PullPolicy - Image pull policy will be performed by: DefaultPullPolicy()
02:00:10.376 [main] INFO  org.testcontainers.utility.ImageNameSubstitutor - Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
02:00:10.869 [main] INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Found Docker environment with Testcontainers Host with tc.host=tcp://127.0.0.1:10185
02:00:10.870 [main] INFO  org.testcontainers.DockerClientFactory - Docker host IP address is 127.0.0.1
02:00:10.936 [main] INFO  org.testcontainers.DockerClientFactory - Connected to docker: 
  Server Version: 78+testcontainerscloud (via Testcontainers Desktop 1.11.0)
  API Version: 1.43
  Operating System: Ubuntu 20.04 LTS
  Total Memory: 7407 MB
02:00:10.947 [main] INFO  org.testcontainers.DockerClientFactory - Checking the system...
02:00:10.947 [main] INFO  org.testcontainers.DockerClientFactory - ✔︎ Docker server version should be at least 1.6.0
02:00:11.006 [main] INFO  tc.postgres:14-alpine - Creating container for image: postgres:14-alpine
02:00:11.216 [main] INFO  org.testcontainers.utility.RegistryAuthLocator - Credential helper/store (docker-credential-desktop) does not have credentials for https://index.docker.io/v1/
02:00:11.226 [main] INFO  tc.testcontainers/ryuk:0.5.1 - Creating container for image: testcontainers/ryuk:0.5.1
02:00:11.445 [main] INFO  tc.testcontainers/ryuk:0.5.1 - Container testcontainers/ryuk:0.5.1 is starting: fe87052cd239947e8da7e6523722f5ace429dfbb4018c3b0f7e8b66fd6920523
02:00:12.072 [main] INFO  tc.testcontainers/ryuk:0.5.1 - Container testcontainers/ryuk:0.5.1 started in PT0.8464625S
02:00:12.581 [main] INFO  tc.postgres:14-alpine - Container postgres:14-alpine is starting: f225800d34ac7488509e2cba684584b827eb0ee133adaaf1f0c38a1882c8865b
02:00:14.138 [main] INFO  tc.postgres:14-alpine - Container postgres:14-alpine started in PT3.1319606S
02:00:14.139 [main] INFO  tc.postgres:14-alpine - Container is started (JDBC URL: jdbc:postgresql://127.0.0.1:32773/test?loggerLevel=OFF)

████████╗███████╗███████╗████████╗ ██████╗ ██████╗ ███╗   ██╗████████╗ █████╗ ██╗███╗   ██╗███████╗██████╗ ███████╗
╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝██╔════╝██╔═══██╗████╗  ██║╚══██╔══╝██╔══██╗██║████╗  ██║██╔════╝██╔══██╗██╔════╝
   ██║   █████╗  ███████╗   ██║   ██║     ██║   ██║██╔██╗ ██║   ██║   ███████║██║██╔██╗ ██║█████╗  ██████╔╝███████╗
   ██║   ██╔══╝  ╚════██║   ██║   ██║     ██║   ██║██║╚██╗██║   ██║   ██╔══██║██║██║╚██╗██║██╔══╝  ██╔══██╗╚════██║
   ██║   ███████╗███████║   ██║   ╚██████╗╚██████╔╝██║ ╚████║   ██║   ██║  ██║██║██║ ╚████║███████╗██║  ██║███████║
   ╚═╝   ╚══════╝╚══════╝   ╚═╝    ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝   ╚═╝   ╚═╝  ╚═╝╚═╝╚═╝  ╚═══╝╚══════╝╚═╝  ╚═╝╚══════╝

  Congratulations on running your first test! 🎉
  Runtime used:
      Testcontainers Cloud via Testcontainers Desktop app

  You can now return to the website to complete your onboarding.


[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.174 s - in cloud.testcontainers.example.TestcontainersCloudFirstTest
[INFO] 
[INFO] Results:
[INFO]
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  7.908 s
[INFO] Finished at: 2024-05-28T02:00:15Z
[INFO] ------------------------------------------------------------------------

These are the commands I used to generate the changes:

cat << EOF > .gitattributes
* text=auto
/.mvn/wrapper/maven-wrapper.properties text
/mvnw text eol=lf
/mvnw.cmd text eol=crlf
EOF

mvn org.apache.maven.plugins:maven-wrapper-plugin:3.3.2:wrapper \
    -Dtype=only-script \
    -Dmaven=3.8.6 \
    -DdistributionSha256Sum=ccf20a80e75a17ffc34d47c5c95c98c39d426ca17d670f09cd91e877072a9309

Closes #21.

@mches mches force-pushed the feature/fix-maven-wrapper branch from df98efe to 769f78f Compare April 29, 2024 20:06
@mches mches changed the title Fix Maven Wrapper Fix Maven Wrapper EOL issues May 12, 2024
@mches mches force-pushed the feature/fix-maven-wrapper branch from 769f78f to 19e31d1 Compare May 28, 2024 00:59
@mches mches force-pushed the feature/fix-maven-wrapper branch from 19e31d1 to 2ecccc5 Compare May 28, 2024 01:54
Copy link
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM.

@kiview kiview merged commit 37e1dde into AtomicJar:main May 28, 2024
1 check failed
@mches mches deleted the feature/fix-maven-wrapper branch May 29, 2024 02:52
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

Successfully merging this pull request may close these issues.

Java Startup Issues During Desktop Verification
2 participants