Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'
like image 884
user1870400 Avatar asked Feb 04 '16 23:02

user1870400


1 Answers

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.

like image 51
Agemo Avatar answered Oct 15 '22 00:10

Agemo