1

My Java application needs to copy artifacts from Artifactory to AWS S3 temp bucket on demand (application group, name and version will be passed as parameters at runtime). The simplest way would be constructing URL and downloading files directly from Artifactory, but application should support 'latest.integration' and 'latest.relase' versions. So I want to add Gradle binaries to the classpath and use it to download dependencies.

Google results overflown with questions about dependency management using build.gradle.

So far I saw https://discuss.gradle.org/t/execute-gradle-task-from-java-code/21859/4 but looks like it also relies on preexisting build.gradle file.

So the question is: is there any way to use Gradle API from Java application to download certain lib without generating build.gradle file?

igor
  • 699
  • 1
  • 9
  • 26
  • You may find something like Ivy (http://ant.apache.org/ivy/) more useful since Gradle is a build framework, not really meant for how you are wanting to use it. – cjstehno Jan 10 '18 at 13:16
  • I already have a code that can download artifacts using Ivy (there is old artifact repo that used for legacy builds). So you mean I can reuse it just change ivysettings.xml? – igor Jan 10 '18 at 13:24
  • You should be able to either change your config or use Ivy as a library to do what you want (with some added code I'm sure). – cjstehno Jan 10 '18 at 13:33
  • You might be interested by the artifactory-java-client written and maintained by JFrog : https://github.com/JFrogDev/artifactory-client-java – jroquelaure Jan 10 '18 at 13:59
  • @cjstehno your suggestion works fine. If you want, you can convert your comment into answer, so I can mark it as correct one. Thanks. – igor Jan 10 '18 at 14:22
  • Related: https://stackoverflow.com/questions/10536221/fetching-maven-artifacts-programmatically – tkruse Jan 10 '18 at 14:29

1 Answers1

1

You should be able to use Ivy (http://ant.apache.org/ivy/) either as is or as a library itself to accomplish what you need, possibly with a bit of additional code.

(answer created from my comments)

cjstehno
  • 13,468
  • 4
  • 44
  • 56