0

Good localtime,

I am in the process of updating legacy (4.8.1) Gradle build files for a big-McLarge-huge, multimodule project. We utilize an intellij.gradle file which has the following line (marked by comment):

idea {
    module {
        inheritOutputDirs = true // <-- HOW DO I DO THIS
        downloadJavadoc = true
        downloadSources = true
    }

    workspace.iws.withXml { provider ->
        def node = provider.asNode()
        def dynamicClasspath = node.component.find { it."@name" == "dynamic.classpath" }
        if (dynamicClasspath != null) {
            dynamicClasspath."@value" = "true"
    }
}

From the 4.8.1 DSL docs:

If true, output directories for this module will be located below the output directory for the project; otherwise, they will be set to the directories specified by IdeaModule.getOutputDir() and IdeaModule.getTestOutputDir().

Any ideas on what the Eclipse DSL equivalent of inheritOutputDirs? Should this be handled using the eclipseClasspath API? Right now everything is building fine, but the Eclipse Java builder is is flagging things.

References:

ShaneK
  • 193
  • 9
  • 1
    Eclipse will output classes to bin directory of project by default. Do you need another arrangement? A description of the errors might help understand what is missing. – emilles Mar 03 '22 at 13:12
  • Best I can tell generated sources, particularly classes from XML, are not being added to the classpath. I haven't been able to confirm this yet. I edited the post to include the contents of the original IntelliJ.gradle file, which I assumed worked. – ShaneK Mar 03 '22 at 22:17
  • 1
    Do you see an example of a generated source that is or isn’t being compiled? Eclipse may need a builder for the generation. If you can describe where class files are being placed it should be easy to then add to the classpath. I suspect some step is missing that builds the class files. – emilles Mar 04 '22 at 00:47
  • They are being generated, in build/cxf/generated-sources/example/full/package/name/class in each project/subproject. For example ... myproject/mysubproject/mysubsubproject/apache/io/commons/someclass.java – ShaneK Mar 04 '22 at 03:06
  • If you are using gradle build to generate these sources, do you have /build/cxf/generated-sources as a source folder in the eclipse project? Or are you looking for eclipse to perform generation as part of its build? – emilles Mar 04 '22 at 10:28
  • They are being created by Gradle, but not listed in source tab for java build path property for each project. I was hoping to configure eclipse.gradle so that it would know to look in that location for all of the projects/subprojects. – ShaneK Mar 04 '22 at 15:07

1 Answers1

1

Usually this would have been picked up through sourceSets but I can't see what your project looks like...

If your subproject uses Gradle to generate sources into /build/cxf/generated-sources directory, then you can tell Eclipse via Gradle DSL to include that as a source folder like this:

plugins { id 'eclipse' }

eclipse.classpath.file.whenMerged {
  // this is the brute-force approach; there is likely a better way to add a source folder
  entries << new org.gradle.plugins.ide.eclipse.model.SourceFolder('build/cxf/generated-sources', null)
}

Once this is run (via gradle eclipseClasspath) you should see a build/cxf/generated-sources folder under your project node in the Package Explorer or Project Explorer. Sort of like this: enter image description here

NOTE: This is untested because I don not have a sample project to work with.

There is more discussion here: How to add gradle generated source folder to Eclipse project?

emilles
  • 1,104
  • 7
  • 14
  • Thanks, this is exactly what I was looking for (and what I was asking about). It turns out something a bit more complicated is going on with our project though. Basically it builds within Eclipse/STS using Gradle Buildship, but the project itself (Java Builder I assume) is still flagging things as unresolvable. Looking through the sub-projects, they are in fact missing classes from build/cxf/generated-sources. That being said, you answered my question ... so thanks for the help. – ShaneK Mar 09 '22 at 18:49