Skip to content

Commit

Permalink
Adds Ivy to the classpath so Groovy scripts can use @grab. Fixes #1. …
Browse files Browse the repository at this point in the history
…Also improves/fixes the build some.
  • Loading branch information
Cervator committed Jun 11, 2017
1 parent 2abb898 commit 23e44aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ dependencies {

task copyToWrapperDir(type: Copy) {
description 'Copies the Groovy wrapper binary to its runtime home with the Graddle wrapper'
from "$buildDir/libs/groovy-wrapper.jar"
dependsOn build
from jar
into 'gradle/wrapper'
rename "-${version}", ""
}

task distZip(type: Zip) {
description 'Makes a zip file containing just the Groovy wrapper binary and scripts'
dependsOn build
dependsOn copyToWrapperDir
from 'gradle/wrapper/groovy-wrapper.jar'
from 'groovyw'
from 'groovyw.bat'
Expand Down
Binary file modified gradle/wrapper/groovy-wrapper.jar
Binary file not shown.
12 changes: 11 additions & 1 deletion src/main/java/org/gradle/wrapper/GroovyBootstrapMainStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class GroovyBootstrapMainStarter extends BootstrapMainStarter {
@Override
public void start(String[] args, File gradleHome) throws Exception {
File groovyJar = findGroovyJar(gradleHome);
URLClassLoader contextClassLoader = new URLClassLoader(new URL[]{groovyJar.toURI().toURL()}, ClassLoader.getSystemClassLoader().getParent());
File ivyJar = findIvyJar(gradleHome);
URLClassLoader contextClassLoader = new URLClassLoader(new URL[]{groovyJar.toURI().toURL(),ivyJar.toURI().toURL()}, ClassLoader.getSystemClassLoader().getParent());
Thread.currentThread().setContextClassLoader(contextClassLoader);
Class<?> mainClass = contextClassLoader.loadClass("groovy.ui.GroovyMain");
Method mainMethod = mainClass.getMethod("main", String[].class);
Expand All @@ -43,4 +44,13 @@ private File findGroovyJar(File gradleHome) {
}
throw new RuntimeException(String.format("Could not locate the Groovy JAR in Gradle distribution '%s'.", gradleHome));
}

private File findIvyJar(File gradleHome) {
for (File file : new File(gradleHome, "lib/plugins").listFiles()) {
if (file.getName().matches("ivy-.*\\.jar")) {
return file;
}
}
throw new RuntimeException(String.format("Could not locate the Ivy JAR in Gradle distribution '%s'.", gradleHome));
}
}

0 comments on commit 23e44aa

Please sign in to comment.