I have a class which implements org.apache.tools.ant.Task.
I am able to run it from within gradle using the ant AntBuilder reference.
In order to do this I have to set the classpath, here is a snippet of the build.gradle file:
I do not understand how the CustomAntTask itself ant the minimum is not on the classpath, and then also how to actually get the classpath to include the rest of the items specified from in the build.gradle file via the ant.taskdef.
I need to be able to load resources from inside the ant task.
You shouldn’t concern yourself with the “java.class.path” system property as this will list Gradle’s bootstrap classpath which isn’t relevant. You’ll be interested in the classloader which loaded your ant task
Try something like
public class CustomAntTask extends Task {
public void execute() {
Classloader loader = getClass().getClassloader();
String pathInsideMyJar = "com/foo/baz.xml";
try (InputStream in = loader.getResourceAsStream(pathInsideMyJar)) {
doStuff(in);
}
}
}