-
Notifications
You must be signed in to change notification settings - Fork 212
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
Potential ways to integrate a task into gradle dependency resolution #1196
Comments
Hi, this is actually something we have dicussed before and possibly something we want to look at doing, there are quite a lot of unknowns though and its far from a trivial amount of work, it would likely require a loom 2.0. The trick of still using a maven repo is neat, but I do still have some concerns/questions that you might be able to help answer.
I will definitely want to keep this issue around, but there are a lot of questions/unknowns to figure out before we even think about going down this route. Its also not like the current approach is fundamentally broken, I know its not propper but it works just fine in 99% of use cases. |
Hi! I'll try to answer the questions as best as I can:
I'll continue implementation and report back if I find anything else interesting 🙂 I'm still in the process of migrating everything to this new method, previously I just attached the tasks to the compilation of a plugin produced by an |
This approach is not dissimilar to how NeoGradle handles setting up the neoforge or minecraft dependency; the major issue that can arise, and arises there, is one of behaviour conf cache behaviour. Namely, I assume your task in question generates a Some more feedback: sticking all the "important" tasks in the root project is not a direction you should be going, as the approach you noted -- |
Hi! I'm working on a very similar gradle plugin (for internal use), and the actual way to how I resolve minecraft is fairly similar to what you do (as far as I've seen):
If I'm not mistaken, I saw that you achieve this by running the steps after project is evaluated. I found this kind of an annoying way to do it, because you loose all the nice benefits from using tasks, like caching and up-to-date checks. Since I apparently have too much time, I looked into this for a long while, and I think I found some interesting things, and I wanted to share them with you in case they are useful :)
This is not a 100% solution, of course, and I only implemented the IDE support for IntelliJ. I saw you also support other IDEs.
This is mainly based on Gradle supporting the following:
dependencies { implementation(files("hello.jar")) }
This way, a file collection can be used as a dependency. Interestingly, a file collection can also carry task dependencies alongside it, and gradle actually supports this for dependencies, mainly so that you can do something like:
This will actually run the
generateJar
task whenever the dependencies are resolved by Gradle. This is sadly kind of useless for our use cases, since IDEs have horrible support for this, and they won't be able to jump into the sources (for example). The IDEs don’t resolve the dependencies, they only go off of the actual maven coordinates you specify. But I found out that you can do this instead:This way
com.test:artifact:1.2.3
can be generated by the task, and gradle will run the task before resolving the dependency (it does not even seem to matter in which order they are specified). But the maven coordinates are also there, which makes the IDE happy.Interestingly, we can also do this now to dynamically handle the dependency requests:
Now, IntelliJ sadly does not give a damn about all this. The
idea-ext
plugin does actually provide a way to specifyafterSync
tasks, but annoyingly, these are executed in a separate run window, and I've noticed in the past that they can be somewhat unreliable. Instead, I looked at how kotlin JS solves this issue - because they have to run things likenpm install
. Turns out, if a tasks namedprepareKotlinIdeaImport
exists, intellij will add that to the requested tasks when syncing... so you can just create one yourself, and it will be executed as part of the IDE sync. I basically just did this:That way, intellij will resolve the compile dependencies, which will also run those tasks (including the dynamic one for the version).
I hope someone finds this useful, maybe the IDEA trick is less hacky than this for example. I simply wasted too much time on it to keep for myself, feel free to just close this of course 😄
(Also, wanted to say thank you for all the amazing tooling the fabric team created. It's great to work with.)
The text was updated successfully, but these errors were encountered: