I am using IntelliJ 14.1.1 (but this issue existed in previous versions) for my gradle project. I have the following for my gradle file:
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
}
It seems like IntelliJ is losing my settings for the generated sources every time I do a gradle build, and I have to go into Project | Module settings, and manually add the src/main/generated/ to the sources.
This usually works, but i don't see why I have to keep telling IntelliJ what my source path is. Is the problem with IntelliJ, or my gradle file?
you can use the following code:
apply plugin: 'idea'
idea {
module {
sourceDirs += file('src/main/generated')
generatedSourceDirs += file('src/main/generated')
}
}