Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pulling a gradle dependency jar from maven and then running it directly?

Tags:

gradle

jar

Is there a way in gradle to specify a dependency (a jar), and then run that jarfile directly within a task?

like image 730
Stefan Kendall Avatar asked Aug 18 '11 17:08

Stefan Kendall


People also ask

Can you use Maven dependencies in Gradle?

Required plugins for adding Gradle dependencies: Maven and Maven Extension. Both plugins are bundled and enabled by default. IntelliJ IDEA lets you add and manage dependencies in your Gradle project. You can add dependencies, and view them in the diagram.

Where are Gradle dependency jars?

Gradle declares dependencies on JAR files inside your project's module_name /libs/ directory (because Gradle reads paths relative to the build.gradle file). This declares a dependency on version 12.3 of the "app-magic" library, inside the "com.example.android" namespace group.

What does -> mean in Gradle dependencies?

It means that dependency graph contains multiple dependencies with the same group and module but different versions for e.g. org.


1 Answers

Here is one way:

configurations {
    tool
}

dependencies {
    tool "some:tool:1.0"
}

task runTool(type: JavaExec) {
    main = "some.tool.Main"
    classpath configurations.tool
}

If you don't know the main class and/or want to do the equivalent of java -jar, you need to employ a workaround as described in http://issues.gradle.org/browse/GRADLE-1274.

like image 94
Peter Niederwieser Avatar answered Sep 28 '22 04:09

Peter Niederwieser