Hello, I am using the Gradle tooling API from Java to run Gradle and I need to use the model to get access to the various modules, their dependencies (and scopes), source, and output directories.
I am attempting to use the Idea Tooling model and this appears to have most of what I would like access:
try (ProjectConnection connection = gradleConnector.connect()) {
GradleProject gradleProject = connection.model(GradleProject.class).get();
IdeaProject ideaProject = connection.model(IdeaProject.class).get();
...
connection.newBuild()
.forTasks(tasks)
.setJvmArguments("-Xmx1g")
.withArguments(excludes)
.run();
I have some code that is mapping an IdeaDependency into a List<Path>
that represents the transitive dependencies and I need to include the output class directory in that list. I am doing the following:
IdeaModule dependencyModule = null;
if (dependency instanceof IdeaModuleDependency) {
String moduleName = ((IdeaModuleDependency) dependency).getTargetModuleName();
dependencyModule = findModule(rootProject, moduleName);
} else if (dependency instanceof BackwardsCompatibleIdeaModuleDependency) {
dependencyModule = ((BackwardsCompatibleIdeaModuleDependency) dependency).getDependencyModule();
}
File outputDirectory = dependencyModule.getCompilerOutput().getOutputDir();
if (outputDirectory != null) {
paths.add(outputDirectory.toPath());
}
And my problem is that the IdeaCompilerOut.getOutputDir() is null and the getInheritOutputDirs()
is false.
I imagine I am just doing something incorrectly here and looking for some guideance.
Thanks!