-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
Packaging Gradle-based applications #17342
Comments
Seconding this. I'd really like to figure this out. |
There is #20444 :-) |
Aye, but Gradle is needed for Android apps |
I am especially interested in building Android apps with Gradle. Recent apps created with Android studio no longer work with ant. I wonder if androidenv can be extended to work with the Gradle wrapper. Or maybe that's not a viable approach. |
Gradle 4.8 was just released. It includes locking of versions, which might be useful for Nix: https://docs.gradle.org/current/release-notes.html#locking-of-dynamic-dependencies |
@bobvanderlinden Very cool, a |
The lock file only includes the groupId, artifactId and the version. See https://docs.gradle.org/current/userguide/dependency_locking.html#_lock_state_location_and_format We still need a way to know the URLs for these packages. |
@bobvanderlinden That's fine. What I'd do is make a Gradle plugin that emits a Nix configuration for a task, and apply it using |
Oh wow. I didn't know Gradle could do that. Nice. https://docs.gradle.org/current/userguide/init_scripts.html#sec:basic_usage
Though I cannot find how to hook into the downloader. Another useful plugin is one that downloads all dependencies: https://github.com/mdietrichstein/gradle-offline-dependencies-plugin |
https://docs.gradle.org/4.8/release-notes.html#locking-of-dynamic-dependencies Fixed link for earlier comment |
So there's a couple of approaches we can take with this. We could write a Another issue with a Gradle plugin solution is that Gradle does not expose any information about dependency resolution, at least not without extreme hacking. The naive implementation, then, would provide a set of source URLs for each artifact, as we have no way of knowing which repository Gradle actually fetched an artifact from without using internal APIs. This is all doable, but ugly. Note that the So I've used another approach recently in https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/security/jd-gui/default.nix, which uses Gradle itself to fetch dependencies, then copies those dependencies from its cache into an offline Maven repository. The entire repository is hashed. This was actually pulled from the mucommander derivation which applied this hack a long time ago to package an application built with Gradle. This approach is far from pure, however, as it cannot be used with sandboxing. So I propose creating a |
Any news here? |
Here's a POC for a It should be able to build itself with the included There are a few pitfalls that I'm working out:
|
I've reworked
|
@tadfisher This looks pretty good, I'm not intimately familiar with gradle, how do I run this if I want to package something? |
You should be able to build the |
+1 |
For later reference, here is an example of something using Gradle without any extra fancy tooling (I think) #72306 |
@deliciouslytyped Unfortunately, that solution will break whenever one of its SNAPSHOT dependencies publishes a new version. In general, you can't make a fixed-output derivation from the dependencies fetched for a build, because Gradle allows dynamic dependency versions and can resolve different artifacts from run to run. Therefore, you need tooling to extract the resolved artifact sources in order to make the build reproducible. |
I made an attempt to use gradle2nix in nixpkgs: #77422 |
Hello, I'm a bot and I thank you in the name of the community for opening this issue. To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human. The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it. If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them. Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel. |
"still important to me" |
I marked this as stale due to inactivity. → More info |
Still important.
…On Jan 4 2021, at 10:27 pm, stale[bot] ***@***.***> wrote:
I marked this as stale due to inactivity. → More info ***@***.***/0?redirect=https%3A%2F%2Fgithub.com%2FNixOS%2Fnixpkgs%2Fblob%2Fmaster%2F.github%2FSTALE-BOT.md&recipient=cmVwbHkrQUNUNUlNNFBKV1RDUFNTVzZDU1U3VE41NzVOVDNFVkJOSEhBVUJKNlRNQHJlcGx5LmdpdGh1Yi5jb20%3D)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub ***@***.***/1?redirect=https%3A%2F%2Fgithub.com%2FNixOS%2Fnixpkgs%2Fissues%2F17342%23issuecomment-754199590&recipient=cmVwbHkrQUNUNUlNNFBKV1RDUFNTVzZDU1U3VE41NzVOVDNFVkJOSEhBVUJKNlRNQHJlcGx5LmdpdGh1Yi5jb20%3D), or unsubscribe ***@***.***/2?redirect=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FACT5IMYOTNU5REXC4TIOX53SYIQD3ANCNFSM4CK5GFQA&recipient=cmVwbHkrQUNUNUlNNFBKV1RDUFNTVzZDU1U3VE41NzVOVDNFVkJOSEhBVUJKNlRNQHJlcGx5LmdpdGh1Yi5jb20%3D).
|
Welp, this is the moment I have been training my whole life. Ahem... It is still important!! Edit: Apparently I am blind, either that or I do not understand meaning of the word "removed". Sorry for ping |
As of Gradle 6.2, Gradle can verify hashes and signatures of artifacts and metadata. See https://docs.gradle.org/current/userguide/dependency_verification.html |
Some updates: #272380 is an effort to have a setup hook available for gradle projects in nixpkgs. NixOS/GSoC#19 is a project proposal for Google Summer of Code to create better gradle tooling. |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
gradle2nix v2 is available for testing, with a novel approach to extracting artifact information by leveraging Gradle's module cache. I have successfully compiled Kotlin from source with it, which is no small feat. Please give it a try, and I intend to contribute this to nixpkgs if all goes well. |
#272380 has been merged and useable for a while now. |
Issue description
I have a (closed) application that I'd like to package and place on my NixOS server. The application can be built using Gradle, however since Gradle downloads its dependencies online it is unable to be build using Nix as-is.
It seemed all application that are based on Java/Ant/Maven/Gradle are being packaged based on binaries, instead of the source. Is this the recommended way to use Java-based applications on Nix?
While trying to find a solution, I have found mvn2nix-maven-plugin, but it was unclear how to use it for other projects. Especially the ones built with Gradle.
The text was updated successfully, but these errors were encountered: