chonton / exists-maven-plugin

Check if artifact exists in remote maven repository
Apache License 2.0
47 stars 18 forks source link

Version 0.7.0 doesn't work when using Amazon S3 #37

Closed jeremywall closed 2 years ago

jeremywall commented 2 years ago

I use maven to package and deploy some common code library jars to an Amazon S3 bucket which serves as a private artifact repository. The deployment to the S3 bucket is done via the org.springframework.build:aws-maven:5.0.0.RELEASE maven extension. The exists-maven-plugin has been fantastic at preventing new builds from overwriting existing deployments but something changed in 0.7.0. It no longer detects the existing deployments and overwrites them every time. When I test against a public artifact repository like Maven Central I see that 0.7.0 always works and detects the existing deployments.

I've run maven with the debug flag and noticed a difference between the HTTP requests that are generated between version 0.6.0 and 0.7.0.

In version 0.7.0 the following HTTP call is logged. I've anonymized and redacted some values but the issue is still clear. In the request generated by version 0.7.0 there is a "%2F" in the URL path (the URL encoded value for a forward slash) that does not appear when I use version 0.6.0.

[DEBUG] Sending request: HEAD /release/%2Fcom/example/commons/215/commons-215.jar HTTP/1.1
[DEBUG] >> HEAD /release/%2Fcom/example/commons/215/commons-215.jar HTTP/1.1
[DEBUG] >> Host: repository.example.com.s3.amazonaws.com
[DEBUG] >> Authorization: *** AWS CREDENTIALS REDACTED ***
[DEBUG] >> User-Agent: aws-sdk-java/1.7.1 Windows_10/10.0 OpenJDK_64-Bit_Server_VM/25.322-b06/1.8.0_322
[DEBUG] >> Date: Fri, 10 Jun 2022 17:38:00 GMT
[DEBUG] >> Content-Type: application/x-www-form-urlencoded; charset=utf-8
[DEBUG] >> Connection: Keep-Alive

[DEBUG] Receiving response: HTTP/1.1 404 Not Found
[DEBUG] << HTTP/1.1 404 Not Found
[DEBUG] << x-amz-request-id: *** REDACTED ***
[DEBUG] << x-amz-id-2: *** REDACTED ***
[DEBUG] << Content-Type: application/xml
[DEBUG] << Date: Fri, 10 Jun 2022 17:38:00 GMT
[DEBUG] << Server: AmazonS3

Under 0.6.0 the URL path that is generated and checked is /release/com/example/commons/215/commons-215.jar which returns an HTTP 200 response and the maven-exists-plugin correctly stops the build and reports that the version is already deployed.

I've done a very basic look through of your code and I don't see anything that changed in 0.7.0 that looks like an immediate culprit for this issue. Could it be the change to Maven 3.8.4 in your plugin's pom.xml?

chonton commented 2 years ago

Please run your build with a -X option. Do you see any log lines starting with 'Fetching '? Does that path have an extra '/'? How is your repository configured? Does it have a trailing slash?

jeremywall commented 2 years ago

I decided to setup a clean demo project to reproduce this. I've posted the project for a dummy demo library at https://github.com/jeremywall/maven-artifact-repo-aws-s3-demo.

I reduced my Maven settings.xml file to the bare minimum and it's shown in the README file at the GitHub repo above.

When using 0.6.0 in the project's pom.xml I can mvn deploy and it will correctly find the existing files in the S3 bucket and stop the build.

When using 0.7.0 in the project's pom.xml and I run mvn deploy it still fails to locate the existing files in the S3 bucket and lets the build continue and at the end the files in S3 are overwritten.

Logs for your Maven plugin when I run mvn deploy -X with both 0.6.0 and 0.7.0 are in the logs folder of the GitHub repo.

From the 0.7.0 log on line 504 you can see the URL path is incorrect with the mystery extra forward slash getting URL encoded as %2F like so:

[DEBUG] Executing request HEAD /release/%2Fdev/jeremywall/mavens3demo/demo-library/1/demo-library-1.jar HTTP/1.1

chonton commented 2 years ago

Please try using 0.8.0-SNAPSHOT

jeremywall commented 2 years ago

No luck I'm afraid, I compiled and installed 0.8.0-SNAPSHOT and when I ran my sample project with that it still has the %2F and can't find the existing jar in the S3 bucket. I've posted the log at https://github.com/jeremywall/maven-artifact-repo-aws-s3-demo/blob/main/logs/exists-maven-plugin-0.8.0-SNAPSHOT.log

chonton commented 2 years ago

@jeremywall, please try with today's updates.

jeremywall commented 2 years ago

SUCCESS!!!

It now detects the existence of the file in S3 and fails with the message "Artifact already exists in repository: dev.jeremywall.mavens3demo:demo-library:jar:1"

The log for this test run is at https://github.com/jeremywall/maven-artifact-repo-aws-s3-demo/blob/main/logs/exists-maven-plugin-0.8.0-SNAPSHOT-round2.log

jeremywall commented 2 years ago

Thank you for the fast turn around and work on resolving this.

chonton commented 2 years ago

Pushed 0.8.0 to central