如何将生成的源文件夹添加到Gradle和IntelliJ中的源路径中? [英] How can I add a generated source folder to my source path in Gradle and IntelliJ?
问题描述
我使用thrift,它会在build目录(build / generated-sources / thrift /< package name> /< class>)下生成一些源文件(接口)但是在我的
src / main / java
下我有我的类,它们与生成的java文件具有相同的包定义,而且我的类还实现了节点生成的接口所以如何在我的 build.gradle 中对此进行配置,以便它可以在i ntelliJ 以及构建中使用
plugins {
idorg.jruyi.thriftversion0.3.1
}
apply plugin:'idea'
apply插件:'java'
apply plugin:'maven'
apply plugin:org.jruyi.thrift
group'com.hello'
version'1.0 -SNAPSHOT'
sourceCompatibility = 1.5
存储库{
mavenCentral()
}
依赖关系{
编译组:'org.apache.thrift',名称:'libthrift',版本:'0.9.3'
c ompile'com.datastax.cassandra:cassandra-driver-core:3.0.0'
compile'com.datastax.cassandra:cassandra-driver-mapping:3.0.0'
testCompile group:'junit' ,名称:'junit',版本:'4.11'
}
compileThrift {
thriftExecutable/ usr / local / hello / bin / thrift
sourceDir src / main / thrift
createGenFolder false
}
任务thrift(类型:Exec){
commandLine'/ usr / local / hello / bin / thrift'
compileJava {
dependsOn'compileThrift'
Gradle构建应该自动工作。
为了使它在Intellij上工作,请尝试将以下内容添加到您的build.gradle中。
idea.module.sourceDirs + = file($ buildDir / generated-sources / thrift)
不要忘记刷新您的gradle项目。
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'
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.
这篇关于如何将生成的源文件夹添加到Gradle和IntelliJ中的源路径中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!