0

I'm looking into migrating from maven to gradle, in this case, gradle itself seems to be working fine, but Idea isn't recognizing the source code that Immutables is generating.

I've read this blog post on APT, it's how I got this for.

/*
 * This build file was generated by the Gradle 'init' task.
 *
 * This generated file contains a commented-out sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/4.3/userguide/tutorial_java_projects.html
 */


// Apply the java plugin to add support for Java
apply plugin: 'java-library'
apply plugin: 'idea'

buildscript {
    repositories {
        maven {
            url 'https://d3vfm0n2cffdwd.cloudfront.net'
        }
        jcenter()
    }
    dependencies {
        classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RELEASE'
    }
}

apply plugin: 'io.spring.dependency-management'

dependencyManagement {
    imports {
        mavenBom 'com.xenoterracide:platform:0.1.39-SNAPSHOT'
    }
}

repositories {
    maven {
        url 'https://d3vfm0n2cffdwd.cloudfront.net'
    }
    jcenter()
}

configurations {
    apt
    aptCompile
}

// In this section you declare the dependencies for your production and test code
dependencies {
    implementation 'com.google.guava:guava'

    aptCompile 'org.immutables:value'
    compileOnly 'org.immutables:value'
    apt 'org.immutables:builder'

    // The production code uses the SLF4J logging API at compile time
    implementation 'org.slf4j:slf4j-api'

    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    testImplementation 'junit:junit'
    testImplementation 'org.assertj:assertj-core'
    testImplementation 'org.mockito:mockito-core'
    testImplementation 'org.hamcrest:hamcrest-library'
}

compileJava {
    options.annotationProcessorPath = configurations.aptCompile
}

for more code see bitbucket

one of the things that's getting me, is that depending on what I've tried the generated java either ends up in an out directory, or build on the classpath, of course so far neither of these solves the problem.

how do I fix this so that Idea can see the source for the generated types (so that it's not all highlighted in red)?

xenoterracide
  • 16,274
  • 24
  • 118
  • 243
  • 1
    See if https://stackoverflow.com/a/46035904/104891 helps. – CrazyCoder Nov 02 '17 at 23:23
  • @CrazyCoder hmm... I don't really need them to share the output directory, just need idea to see the generated sources when it compiles. – xenoterracide Nov 02 '17 at 23:41
  • See https://youtrack.jetbrains.com/issue/IDEA-152581 for the related issue that was fixed some time ago. If your issue is different, please report it at https://youtrack.jetbrains.com/issues/IDEA. – CrazyCoder Nov 02 '17 at 23:45
  • @CrazyCoder probably related, the problem (in addition to needing to uncheck create separate module per source set) with highlighting seems to be that `out/production/classes/generated` is not marked as a generated sources directory , so even though the compiler recognizes things, the syntax highlighter doesn't. I'm uncertain if that's a new issue 2017.2.5 – xenoterracide Nov 03 '17 at 00:15
  • or is it `target/generated-sources/annotatons` very confused at how directories are getting set, but the larger problem is that idea isn't auto adding them as the generated source directory – xenoterracide Nov 03 '17 at 00:22
  • https://youtrack.jetbrains.com/issue/IDEA-150042 might be the case. – CrazyCoder Nov 03 '17 at 00:45

1 Answers1

3

@CrazyCoder's links helped me get closer to a solution, this seems to resolve it though.

idea {
    module {
        sourceDirs += file("out/production/classes/generated")
    }
}
xenoterracide
  • 16,274
  • 24
  • 118
  • 243