mrVoid
mrVoid

Reputation: 995

Gradle - get artifact from repository and use it

The problem:

I have a jar in some repository.
I want to run the jar and do something with it during gradle task.

The attempt:

apply plugin: 'java'

repositories {
  maven {
    url "<<<valid repo url>>>"
  }
  mavenCentral()
}

dependencies {
  compile(group: 'com.google.developers', name: 'compiler', version: 'v20150315', ext: 'pom')
}

task doTheJar {
  dependsOn configurations.compile
  exec {
    executable "sh"
    args "-c","java -jar <<the-artifact>> smoething something"
  }
}

Is there a way to do it? Is there a way to do it without java plugin?

Thanks.

Upvotes: 1

Views: 1766

Answers (1)

Opal
Opal

Reputation: 84756

It will be better to do it in the following way:

apply plugin: 'java'

repositories {
  maven {
    url "<<<valid repo url>>>"
  }
  mavenCentral()
}

configurations {
   runjar
}

dependencies {
  runjar 'some:artifact:1.0'
}

task runTheJar(type: JavaExec) {
   main 'main.class.to.be.run'
   classpath configurations.runjar
   args 's1', 's2', 's3'
}

Upvotes: 2

Related Questions