Force IntelliJ IDEA build directories

From IntelliJ IDEA 2017.2 the default build directory is out/ and not
build/ when importing Gradle projects. In our tests we use the class-files
from the build directory, so ensure IntelliJ still uses build/.

Change-Id: I484826f795545a150c1e22d59f3d7843fed470ca
diff --git a/build.gradle b/build.gradle
index c351aca..8a5830d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -12,6 +12,17 @@
 apply plugin: 'net.ltgt.errorprone-base'
 apply plugin: "net.ltgt.apt"
 
+// Ensure importing into IntelliJ IDEA use the same output directories as Gradle. In tests we
+// use the output path for tests (ultimately through ToolHelper.getClassPathForTests()) and
+// therefore these paths need to be the same. See https://youtrack.jetbrains.com/issue/IDEA-175172
+// for context.
+idea {
+    module {
+        outputDir file('build/classes/main')
+        testOutputDir file('build/classes/test')
+    }
+}
+
 def errorProneConfiguration = [
     '-XepDisableAllChecks',
     // D8 want to use reference equality, thus disable the checker explicitly