Search code examples
jargradleartifact

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.


Solution

  • 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'
    }