How to get a reference of a jar file when knowing "groupId:artifactId:version" info?

how to get a reference of a jar file from “groupId:artifactId:version” info? Because I have a method with a file parameter - analyze(File jar), and at that point I know “groupId:artifactId:version” info. I’m think there could have some API to handle this.

Thanks in advance

I assume you are talking about a JAR file declared as dependency in your build script? Here’s an example:

configurations {
    myConf
}
  dependencies {
    myConf 'commons-lang:commons-lang:2.5'
}
  repositories {
    mavenCentral()
}
  def myDep = configurations.myConf.files { dep -> dep.group == 'commons-lang' && dep.name == 'commons-lang' && dep.version == '2.5' }
  task printDep << {
    println myDep
}

Benjamin, thank you for your quick replying.

I sorry, I didn’t clear that I’m writing a Gradle plugin, I need the jar file inside my @TaskAction method.

@TaskAction

def jarProcess() {

“group:artifactId:version”

analyze(File jar)

}

Additionally, the “group:artifactId:version” may or maynot declared in build.gradle. For my purpose, it’s best to call one repository API to do this.

I’m guessing

repositoryAPI.download(“group”, “artifactId”, “version”)

If you have any idea about this, really appreciate it

You can achieve similar things within a custom task. Remember that you always have a reference to the Project instance via the property “project”.