Skip to content

Commit

Permalink
Build: use separate build directories for eclipse and intellij
Browse files Browse the repository at this point in the history
This fixes the problem where doing a gradle clean from the command line
completely breaks the IDE.
  • Loading branch information
rjernst committed Feb 4, 2016
1 parent 7a6adfd commit 2fef5de
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
*.iml
*.ipr
*.iws
build-idea/

# eclipse files
.project
.classpath
eclipse-build
.settings
build-eclipse/

# netbeans files
nb-configuration.xml
Expand All @@ -18,7 +19,6 @@ nbactions.xml
# gradle stuff
.gradle/
build/
generated-resources/

# maven stuff (to be removed when trunk becomes 4.x)
*-execution-hints.log
Expand All @@ -38,5 +38,5 @@ html_docs
# random old stuff that we should look at the necessity of...
/tmp/
backwards/

eclipse-build

19 changes: 14 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ subprojects {
allprojects {
// injecting groovy property variables into all projects
project.ext {
// for eclipse hacks...
// for ide hacks...
isEclipse = System.getProperty("eclipse.launcher") != null || gradle.startParameter.taskNames.contains('eclipse') || gradle.startParameter.taskNames.contains('cleanEclipse')
isIdea = System.getProperty("idea.active") != null || gradle.startParameter.taskNames.contains('idea') || gradle.startParameter.taskNames.contains('cleanIdea')
}
}

Expand Down Expand Up @@ -170,12 +171,15 @@ gradle.projectsEvaluated {
allprojects {
apply plugin: 'idea'

if (isIdea) {
project.buildDir = file('build-idea')
}
idea {
module {
// same as for the IntelliJ Gradle tooling integration
inheritOutputDirs = false
outputDir = file('build/classes/main')
testOutputDir = file('build/classes/test')
outputDir = file('build-idea/classes/main')
testOutputDir = file('build-idea/classes/test')

iml {
// fix so that Gradle idea plugin properly generates support for resource folders
Expand Down Expand Up @@ -222,14 +226,19 @@ allprojects {
apply plugin: 'eclipse'

plugins.withType(JavaBasePlugin) {
eclipse.classpath.defaultOutputDir = new File(project.buildDir, 'eclipse')
File eclipseBuild = project.file('build-eclipse')
eclipse.classpath.defaultOutputDir = eclipseBuild
if (isEclipse) {
// set this so generated dirs will be relative to eclipse build
project.buildDir = eclipseBuild
}
eclipse.classpath.file.whenMerged { classpath ->
// give each source folder a unique corresponding output folder
int i = 0;
classpath.entries.findAll { it instanceof SourceFolder }.each { folder ->
i++;
// this is *NOT* a path or a file.
folder.output = "build/eclipse/" + i
folder.output = "build-eclipse/" + i
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extraArchive {

eclipse {
classpath {
defaultOutputDir = new File(file('build'), 'eclipse')
defaultOutputDir = file('build-eclipse')
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.gradle.api.tasks.Copy
class PluginPropertiesTask extends Copy {

PluginPropertiesExtension extension
File generatedResourcesDir = new File(project.projectDir, 'generated-resources')
File generatedResourcesDir = new File(project.buildDir, 'generated-resources')

PluginPropertiesTask() {
File templateFile = new File(project.buildDir, 'templates/plugin-descriptor.properties')
Expand Down

0 comments on commit 2fef5de

Please sign in to comment.