How can I add a generated source folder to my source path in Gradle and IntelliJ?

倖福魔咒の 提交于 2019-12-07 05:19:21

问题


I use thrift and it generates some source java files(interfaces) under build directory (build/generated-sources/thrift/<package name>/<class>) but under my src/main/java I have my classes which has the same package definition as in the generated java files and my classes also implements the interfaces generated by the thrift so how can I configure this in my build.gradle so it works on intelliJ as well as the build

plugins {
  id "org.jruyi.thrift" version "0.3.1"
}
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: "org.jruyi.thrift"

group 'com.hello'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.5

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.apache.thrift', name: 'libthrift', version:'0.9.3'
    compile 'com.datastax.cassandra:cassandra-driver-core:3.0.0'
    compile 'com.datastax.cassandra:cassandra-driver-mapping:3.0.0'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

compileThrift {
    thriftExecutable "/usr/local/hello/bin/thrift"
    sourceDir "src/main/thrift"
    createGenFolder false
}

task thrift(type: Exec) {
    commandLine '/usr/local/hello/bin/thrift'
}


compileJava {
    dependsOn 'compileThrift'

回答1:


The gradle build should work automatically. To make it work on Intellij, try adding the following to your build.gradle.

idea.module.sourceDirs += file("$buildDir/generated-sources/thrift")

Don't forget to refresh your gradle projects.



来源:https://stackoverflow.com/questions/35213894/how-can-i-add-a-generated-source-folder-to-my-source-path-in-gradle-and-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!