IntelliJ与gradle和querydsl

时间:2015-04-17 03:53:50

标签: gradle intellij-14

我正在使用IntelliJ 14.1.1(但此问题存在于以前的版本中)用于我的gradle项目。我的gradle文件有以下内容:

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'maven'

project.ext {
    springBootVersion = '1.1.7.RELEASE'
}

configurations {
    querydslapt
}

jacoco {
    toolVersion = "0.7.0.201403182114"
}

buildscript {
    repositories {
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
        maven { url "http://repo.spring.io/libs-milestone" }
        maven { url "http://repo.spring.io/libs-snapshot" }
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.3.RELEASE")
    }
}

jar {
   ...
}

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-milestone" }
    ...
}

jacocoTestReport {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

//Querydsl
def generatedSrcDir = 'src/main/generated'
task createGeneratedSrcDir << {
    file(generatedSrcDir).mkdirs()
}
compileJava.dependsOn createGeneratedSrcDir
compileJava {
    options.compilerArgs << '-processor' << 'com.mysema.query.apt.jpa.JPAAnnotationProcessor' << '-s' << file(generatedSrcDir).absolutePath
}
clean {
    delete generatedSrcDir
}  

似乎IntelliJ每次进行gradle构建时都会丢失我为生成的源设置的设置,而且我必须进入Project |模块设置,并手动将src / main / generated /添加到源。

这通常有效,但我不知道为什么我要告诉IntelliJ我的源路径是什么。 IntelliJ或我的gradle文件有问题吗?

1 个答案:

答案 0 :(得分:3)

您可以使用以下代码:

apply plugin: 'idea'
idea {
module {
    sourceDirs += file('src/main/generated')
    generatedSourceDirs += file('src/main/generated')
 }
}