Hi everyone, I am looking for a way to download d...
# community-support
j
Hi everyone, I am looking for a way to download dependency sources in Gradle (without using Eclipse, Intellij or any other IDE). Is there currently a way of doing this? Maybe a plugin? Thank you
a
hi 👋 Yes, it's possible to download sources (I'm assuming you mean Java sources) There's a whole demo project here https://github.com/gradle/source-resolution-demo, but don't be intimidated by the size, it's a lot more complicated than it needs to be for some reason. The summary of what you need to do is to is: 1. create a Configuration for declaring dependencies 2. create another Configuration for resolving the declared dependencies 3. Set the correct Attributes on the resolving Configuration that say "I want to download Java sources" 4. define a task that will resolve the Configuration
Something like this :) (written with Gradle 8.6)
j
@Adam this is great, thank you very much! I will take a look
Do you know how much backwards compatible this solution is?
a
my pleasure!
backwards compatible in what regard? With different Gradle versions?
j
Yes, with older Gradle versions
a
isCanBeDeclared
is newer, Gradle 8.something, but the rest should be compatible with even very old versions
j
👍 great, thanks for the info
a
no probs!
j
Hey @Adam, hope you don't mind me reopening this thread again. I have modified and adapted the sources download bit in
source-resolution-demo
to be able to use it as a binary plugin (as a JAR file), but when trying to run it as part of the build of a sample project, the runtimeClasspath variable is not found:
Copy code
* What went wrong:
An exception occurred applying plugin request [id: 'org.konveyor.java.plugin', version: '1.0-SNAPSHOT']
> Failed to apply plugin [id 'org.konveyor.java.plugin']
   > Configuration with name 'runtimeClasspath' not found.
I have basically included it in my sample project's build file as:
Copy code
plugins {
    [...]
    id 'org.konveyor.java.plugin' version '1.0-SNAPSHOT'
}
which seems to work up to that point...
a
hey, I don't mind at all!
My first guess is that you need to 'react' to the Java plugin, to ensure that the configuration has been created https://docs.gradle.org/8.7/userguide/implementing_gradle_plugins_binary.html#reacting_to_plugins
j
So my plugin must be explicitly "aware" of the presence of the Java plugin in order to be able to grab the
runtimeClasspath
config, so to speak
a
Basically, yes. It's an ordering problem. Alternatively, you can make your plugin opinionated and make it apply the Java plugin automatically.
Copy code
project.pluginManager.apply("java")
(I think that's right)
j
Thanks man, got it working! 🙏
🤘 1