-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Move desugar to a standalone project #2975
Comments
Hi @balazs-zsoldos , there is a standalone repo containing the desugar within the Android platform's code base: https://android.googlesource.com/platform/external/desugar. It is being integrated with Gradle in an upcoming Android Studio release: https://developer.android.com/studio/preview/features/java8-support.html. Does this fit your use case? I'll leave it up to @kevin1e100 , author of desugar, for comment on if there are any plans to publish a jar to maven central. |
Hi @aj-michael, we already downloaded the Android Studio Preview. However, our use-case a bit special :-). We want to repack an OSGi based application to be used on an Android tablet. We add each dependencies to the project as an asset. So in the gradle script:
What we could not do is to call Desugar on a JAR file from the gradle script. We could do it only in the way that we re-packaged Desugar and created an executable JAR from it. Is there a way to call Desugar as a library from the Gradle script? Also in the long term, I think people would really appreciate it if Desugar could be used as a standalone lib or command-line tool. It would be very useful not only in other projects (not only in Android studio and/or Basel). That is why I asked if it could be uploaded to Maven Central. In that case, it could be accessed by everyone from any tool. |
I am not very familiar with Gradle scripts, so I can't advise on how to invoke Desugar from a Gradle script. To partially answer your question, Desugar already is a standalone command-line tool. Bazel treats it as a standalone command-line tool. It just so happens that command-line tool is bundled inside of the standard Bazel distribution. Here are the steps to build and use the command-line desugar tool:
|
@aj-michael Thanks a lot for the answer! It will be easier for us in the future to build Desugar in the standard way. The company computer is a Windows machine and there I could neither install or compile Bazel due to missing reqs (e.g.: windows SDK or it could not find msys64), but I guess time will solve this issue, and there will be an easily downloadable binary that works out-of-the-box. You can close this issue if you want, or leave it until you decide if you upload desugar to maven-central with a pom that has the dependencies (which I think would be useful for others who would use maven to desugar java 8 code). |
This will make it easier to build the desugarer tool from the Bazel source tree as an executable (deploy) jar and then use it for something else. For example, with this CL, you can do the following steps to get a standalone desugarer binary: 1. git clone https://github.com/bazelbuild/bazel 2. bazel build //src/tools/android/java/com/google/devtools/build/android/desugar:desugar_bin_deploy.jar 3. cp bazel-bin/src/tools/android/java/com/google/devtools/build/android/desugar/desugar_bin_deploy.jar ~/bin/desugar.jar And then you can invoke desugar without bazel with `java -jar ~/bin/desugar.jar`. #2975 RELNOTES: None PiperOrigin-RevId: 155629711
(standing in for @kevin1e100, who is OOO) We're sorry, but we have no plans to publish Desugar as a separate tool. Our team is lightly staffed for this, and our priority is Bazel and Android Studio customers. There are some workarounds in this thread, and I hope they are sufficient for your use case. |
Marking this as closed per @eaftan's comment. @kevin1e100 can reopen if plans change. |
@aj-michael thank you sir, can you send your desugar_bin_deploy.jar ? i used your command : result :
|
Correct build/run instructions are:
|
The code seems to have been updated and the build commands no longer work. I had to reset to the commit git reset --hard f78ffb5fb2f37d20acd1320ed37080c26b32e607
bazel build //src/tools/android/java/com/google/devtools/build/android/desugar:Desugar_deploy.jar
cp bazel-bin/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar_deploy.jar desugar_deploy.jar
java -jar bazel-bin/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar_deploy.jar but the problem is, it's giving me errors when i run it on my machine.
I also found this reddit post that suggests using rt.jar, should i try downloading rt.jar from jdk8? |
If you could, please, move Desugar out to a separate project, it would be great. Reasons:
If it is possible, please upload the Desugar jar with a descriptive pom (containing its dependencies) to maven-central.
Btw.: We moved out the code of Desugar and recompiled it as a JAR file. The only thing we had to do is removing the dependency on the com.google.devtools.build.android.Converters class and all dependencies could be downloaded from maven-central. The tool works great (although it has some bugs, fits our needs much better than the retrolambda project). Please do this step before it is too late, before the Desugar source code is wired too much together with the remaining part of Bazel code.
The text was updated successfully, but these errors were encountered: