6

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' 
4
  • Does thrift generate those sources via gradle? Commented Feb 4, 2016 at 23:56
  • yes. I attached my gradle file Commented Feb 5, 2016 at 1:14
  • 1
    How about: sourceSets.main.java { srcDir "$buildDir/generated-sources/thrift" } Commented Feb 5, 2016 at 2:29
  • Who is this doppleganger?!? Seriously, what are the odds that these 2 questions would be asked on the same exact day... Commented Feb 5, 2016 at 20:25

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.