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

sbt-sonatype sonatypeBundleRelease failed use Java8 #548

Open
djx314 opened this issue Nov 18, 2024 · 12 comments
Open

sbt-sonatype sonatypeBundleRelease failed use Java8 #548

djx314 opened this issue Nov 18, 2024 · 12 comments

Comments

@djx314
Copy link

djx314 commented Nov 18, 2024

sbt-sonatype sonatypeBundleRelease failed use Java8.
This command succeed in Java17. It seems that https://github.com/lumidion/sonatype-central-client use HttpURLConnectionBackend.
But bundle.zip is also generated in Java8 though sonatypeBundleRelease failed.

[info]  published sbt-depts-djx314_2.12_1.0 to D:\f\programming\sbt-depts\inner-project\target\sonatype-staging\0.0.1-M1072\net\scalax\djx314\sbt-depts-djx314_2.12_1.0\0.0.1-M1072.part\sbt-depts-djx314_2.12_1.0-0.0.1-M1072.jar.asc                                                                                                                                                                                                                          
[info]  publish commited: moved D:\f\programming\sbt-depts\inner-project\target\sonatype-staging\0.0.1-M1072\net\scalax\djx314\sbt-depts-djx314_2.12_1.0\0.0.1-M1072.part
[info]          to D:\f\programming\sbt-depts\inner-project\target\sonatype-staging\0.0.1-M1072\net\scalax\djx314\sbt-depts-djx314_2.12_1.0\0.0.1-M1072                                                                         
[success] Total time: 9 s, completed 2024-11-19 4:33:25                                                                                                                                                                         
sbt:sbt-depts-root> sonatypeBundleRelease 
2024-11-19 04:34:31.282+0800  info [SonatypeCentralClient] Uploading bundle D:\f\programming\sbt-depts\inner-project\target\sonatype-staging\0.0.1-M1072-bundle\bundle.zip to Sonatype Central  - (SonatypeCentralClient.scala:72)
2024-11-19 04:34:31.356+0800 error [Sonatype] [GENERIC_ERROR] java/net/http/HttpTimeoutException  - (Sonatype.scala:494)
sbt:sbt-depts-root>

Suggestion

  1. Make Http Backend compat to Java8.
  2. Make zip to bundle.zip a single task, that I can upload to maven as a zip file just use sbt and no need to use 7-zip.

https://github.com/lumidion/sbt-sonatype-central/blob/94390e57822176aa919aeb9859faf610e2fafa07/src/main/scala/com/lumidion/sbt/sonatype/central/SonatypeCentralService.scala#L33

https://github.com/lumidion/sbt-sonatype-central/blob/94390e57822176aa919aeb9859faf610e2fafa07/src/main/scala/com/lumidion/sbt/sonatype/central/SonatypeCentralService.scala#L51-L93

@djx314
Copy link
Author

djx314 commented Nov 19, 2024

图片

@xerial I use sbt-sonatype to run ; publishSigned; sonatypeBundleRelease;, it's error but gen bundle.zip succeed. Than I just use maven UI to upload this zip file. It's perfect and I can revoke my user token though I just have 3 - 5 projects to publish to maven.

And the zip file can upload with curl that we do not need to put the user token in project configuration. The curl command is very short and show in the swagger UI in maven central and maven central doc, so it's easy to write it manual in CI.

Now I just run ; publishSigned;, and use 7-zip to package the directory. Then publish the zip file use maven UI. It works for my repo. So I think the package task that gen bundle.zip mybe a important step that can make it a single task.

@xerial
Copy link
Owner

xerial commented Nov 20, 2024

Thanks for the report. Unfortunately, however, I don't have much control over the behavior of sonatype-central-client library, so the fix should first be made there.

An ideal direction for me is:

@djx314
Copy link
Author

djx314 commented Nov 20, 2024

backend = Slf4jLoggingBackend(HttpURLConnectionBackend())

@xerial I think change import sttp.client4.httpurlconnection.HttpURLConnectionBackend to other backend can solve the problem.

图片

The readme.md in https://github.com/lumidion/sonatype-central-client is also allow user to set the backend manual.

Default HttpURLConnectionBackend use JDK's default http implemention. So it's easy to cause some JDK version problems.

@Andrapyre
Copy link
Contributor

@adamw, do you have any advice for building sttp backends with Java 8? I wasn't able to get either the OkHttpSyncBackend or the HttpURLConnectionBackend to run, although OkHttp itself claims to support Java 8.

@adamw
Copy link

adamw commented Nov 22, 2024

@Andrapyre What kind of errors are you getting? I haven't tried Java 8 for a long time now, but at some point we did switch to building on Java 11 - that should be findable in the release notes (though this was a long time ago as well)

@Andrapyre
Copy link
Contributor

@Andrapyre What kind of errors are you getting? I haven't tried Java 8 for a long time now, but at some point we did switch to building on Java 11 - that should be findable in the release notes (though this was a long time ago as well)

Here is the ticket for the error in the sonatype central client. lumidion/sonatype-central-client#11

The error seems to imply that the code itself was compiled beforehand in Java 11 before being compiled to Java 8. I am cleaning the environment before compiling, so it shouldn't be an environment problem. Does the lib itself contain any precompiled classes?

@adamw
Copy link

adamw commented Nov 25, 2024

@Andrapyre no, nothing is pre-compiled. So if you are building from scratch, you must have something cached somewhere.

@Andrapyre
Copy link
Contributor

@adamw , I had forgotten that (unlike in languages like Rust, where you get the source code directly in the lib) all JVM libs are compiled to Java byte code already (like in this jar), so of course this would generate an error for Java 8, if the libs are being built and published on a Java 11 machine.

I will try to create a backend that is compatible with Java 8 in the next few days. HttpURLConnectionBackend is built on HttpClient, which ships with Java 11, so that's out. Refactoring the OkHttp backend seems more feasible. I'll see if I can get that to work. Following updates will be in this ticket: lumidion/sonatype-central-client#11

@adamw
Copy link

adamw commented Nov 26, 2024

@Andrapyre The HttpURLConnectionBackend is built on HttpURLConnection, which is in Java since ... well, definitely before Java 8. So this should work fine. HttpClient[...]Backend on the other hand, is based on HttpClient, which is Java 11+ only. So you should be good with HttpURLConnectionBackend

@Andrapyre
Copy link
Contributor

Andrapyre commented Nov 27, 2024

@djx314 , sonatype-central-client supports two clients, one based on requests (used in mill) and one based on sttp (used in sbt). Neither, it seems, work on Java 8 (though both work with Java 11) and I would need to add support for another completely separate client, probably either OkHttp or airframe (if @xerial can add support for multipart uploads). Before I do that, can I ask if you could just solve this by upgrading to Java 11? It doesn't look like this request is too common.

I've put more context for the issues with sttp here.

@djx314
Copy link
Author

djx314 commented Nov 27, 2024

@djx314 , sonatype-central-client supports two clients, one based on requests (used in mill) and one based on sttp (used in sbt). Neither, it seems, work on Java 8 (though both work with Java 11) and I would need to add support for another completely separate client, probably either OkHttp or airframe (if @xerial can add support for multipart uploads). Before I do that, can I ask if you could just solve this by upgrading to Java 11? It doesn't look like this request is too common.

I've put more context for the issues with sttp here.

@Andrapyre

1

Use a special http client abstraction is the best. lumidion/sonatype-central-client just need to define a trait with 3 - 5 http method that can finished all the http action. Then lumidion/sonatype-central-client no need to bind any special http client.

2

My workaround is discribed in this page.

#548 (comment)

Just set

publishTo := sonatypePublishToBundle.value

to all project.

// build.sbt
`project1` / publishTo := (`project1` / sonatypePublishToBundle).value
`project2` / publishTo := (`project2` / sonatypePublishToBundle).value
`project3` / publishTo := (`project3` / sonatypePublishToBundle).value
`project4` / publishTo := (`project4` / sonatypePublishToBundle).value
`project1` / publishTo := (`project1` / sonatypePublishToBundle).value

publishSigned will push all the files to rootProject/target/sonatype-staging/latest-version/( sbt-pgp is been used ).
sonatypeBundleRelease will do two things.

  1. Zip the dirctory rootProject/target/sonatype-staging/latest-version/ to rootProject/target/sonatype-staging/latest-version-bundle/bundle.zip. This step run successed. It's the same as 7z the directory to a zip file.
  2. Send rootProject/target/sonatype-staging/latest-version-bundle/bundle.zip to maven. Just this step is failed.

I 7z the rootProject/target/sonatype-staging/latest-version/ directiory to bundle.zip and push bundle.zip use maven ui ( or use curl in ci ). It works for me.

387874151-01a51ca8-bb19-4838-a175-ef89be2e3a84

Now I already removed all the credentials setting in single file sonatype.sbt and remove the path in .gitignore. Beacuse I just need to manage 3 - 5 scala repo in maven.

@rafafrdz
Copy link

rafafrdz commented Dec 23, 2024

For those of you using sbt-ci-release and/or sbt-sonatype for GitHub Action deployments (while this issue is fixed), consider changing the Java version from 8 to 11—it works!

See in my repo: eff3ct0/teckel@89d9502

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

5 participants