I have a task that is producing a jar outside of the java plugin (running an external tool). I would like it so any project that includes the project that gens this jar to use it as part of their classpath. I don’t want to just add this jar to the dependencies section, as it is being generated by a task in this project (not pre-gen).
I would like to, on my consumer project, just do this and have it compile against the produced jar, just as if gradle had compiled it (Well, not exactly, since gradle pulls in the classes folder, and this is a jar, but functionally the same):
task genProject //Makes a jar
//This would seem to be the way to do this, but no luck
Configuration compileConfig = project.getConfigurations().add(JavaPlugin.COMPILE_CONFIGURATION_NAME);
artifacts {
compileConfig file new File(project.buildDir, "someOutputJar"), builtBy: genProject
}
task compileJava (dependsOn: genProject);
This works to have my genProject code called at the right time, but I am not getting the jar onto the classpath.
Both of these methods work if the java plugin is applied to the project producing the jar. However, I was hoping to not apply that plugin, as it does no work on the project (the jar is created by an external utility), and so adding all the tasks from the Java plugin is silly, as they do nothing.
Since adding the plugin got it working, I’ll leave it, but it means that when java builds happen, this project run empty tasks, which could possibly cause confusion later down the road
I don’t see why the producing project would have to apply the ‘java’ plugin. Should be good enough to apply the ‘base’ or ‘java-base’ plugin, and add the artifact to the ‘default’ configuration (or your own).
PS: A project dependency on a ‘java’ project does get resolved to the Jar (not the classes folder).