Initial configuration for new gradle setup
This is the first step towards cleaning up our build.gradle file by
moving to a new version. tools/gradle.py and tools/test.py should still
work the same.
Bug: b/270105162
Change-Id: I157cc9314dbdd4a0580f9351a6e0bb8c99b3a386
diff --git a/d8_r8/gradle.properties b/d8_r8/gradle.properties
new file mode 100644
index 0000000..ef0be28
--- /dev/null
+++ b/d8_r8/gradle.properties
@@ -0,0 +1,17 @@
+# Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8
+kotlin.daemon.jvmargs=-Xmx3g -Dkotlin.js.compiler.legacy.force_enabled=true
+systemProp.file.encoding=UTF-8
+
+# Enable new incremental compilation
+kotlin.incremental.useClasspathSnapshot=true
+
+org.gradle.parallel=true
+org.gradle.caching=true
+
+# Do not download any jdks or detect them. We provide them
+org.gradle.java.installations.auto-detect=false
+org.gradle.java.installations.auto-download=false
diff --git a/d8_r8/keepanno/build.gradle.kts b/d8_r8/keepanno/build.gradle.kts
new file mode 100644
index 0000000..b7a2acf
--- /dev/null
+++ b/d8_r8/keepanno/build.gradle.kts
@@ -0,0 +1,21 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+plugins {
+ `kotlin-dsl`
+ id("dependencies-plugin")
+}
+
+java {
+ sourceSets.main.configure {
+ java.srcDir(getRoot().resolveAll("src", "keepanno", "java"))
+ }
+ sourceCompatibility = JvmCompatibility.sourceCompatibility
+ targetCompatibility = JvmCompatibility.targetCompatibility
+}
+
+dependencies {
+ compileOnly(Deps.asm)
+ compileOnly(Deps.guava)
+}
diff --git a/d8_r8/keepanno/gradle.properties b/d8_r8/keepanno/gradle.properties
new file mode 100644
index 0000000..ef0be28
--- /dev/null
+++ b/d8_r8/keepanno/gradle.properties
@@ -0,0 +1,17 @@
+# Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8
+kotlin.daemon.jvmargs=-Xmx3g -Dkotlin.js.compiler.legacy.force_enabled=true
+systemProp.file.encoding=UTF-8
+
+# Enable new incremental compilation
+kotlin.incremental.useClasspathSnapshot=true
+
+org.gradle.parallel=true
+org.gradle.caching=true
+
+# Do not download any jdks or detect them. We provide them
+org.gradle.java.installations.auto-detect=false
+org.gradle.java.installations.auto-download=false
diff --git a/d8_r8/keepanno/settings.gradle.kts b/d8_r8/keepanno/settings.gradle.kts
new file mode 100644
index 0000000..7b4d459
--- /dev/null
+++ b/d8_r8/keepanno/settings.gradle.kts
@@ -0,0 +1,18 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+pluginManagement {
+ repositories {
+ gradlePluginPortal()
+ }
+}
+
+dependencyResolutionManagement {
+ repositories {
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+
+rootProject.name = "keepanno"
diff --git a/d8_r8/main/build.gradle.kts b/d8_r8/main/build.gradle.kts
new file mode 100644
index 0000000..e664753
--- /dev/null
+++ b/d8_r8/main/build.gradle.kts
@@ -0,0 +1,33 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+plugins {
+ `kotlin-dsl`
+ id("dependencies-plugin")
+}
+
+java {
+ sourceSets.main.configure {
+ java.srcDir(getRoot().resolveAll("src", "main", "java"))
+ resources.srcDirs(getRoot().resolveAll("third_party", "api_database", "api_database"))
+ }
+ sourceCompatibility = JvmCompatibility.sourceCompatibility
+ targetCompatibility = JvmCompatibility.targetCompatibility
+}
+
+dependencies {
+ implementation(":keepanno")
+ implementation(Deps.asm)
+ implementation(Deps.asmUtil)
+ implementation(Deps.asmCommons)
+ implementation(Deps.fastUtil)
+ implementation(Deps.gson)
+ implementation(Deps.guava)
+ implementation(Deps.joptSimple)
+ implementation(Deps.kotlinMetadata)
+}
+
+tasks.withType<JavaCompile> {
+ println("NOTE: Running with JDK: " + org.gradle.internal.jvm.Jvm.current().javaHome)
+}
diff --git a/d8_r8/main/gradle.properties b/d8_r8/main/gradle.properties
new file mode 100644
index 0000000..ef0be28
--- /dev/null
+++ b/d8_r8/main/gradle.properties
@@ -0,0 +1,17 @@
+# Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8
+kotlin.daemon.jvmargs=-Xmx3g -Dkotlin.js.compiler.legacy.force_enabled=true
+systemProp.file.encoding=UTF-8
+
+# Enable new incremental compilation
+kotlin.incremental.useClasspathSnapshot=true
+
+org.gradle.parallel=true
+org.gradle.caching=true
+
+# Do not download any jdks or detect them. We provide them
+org.gradle.java.installations.auto-detect=false
+org.gradle.java.installations.auto-download=false
diff --git a/d8_r8/main/settings.gradle.kts b/d8_r8/main/settings.gradle.kts
new file mode 100644
index 0000000..2d727f0
--- /dev/null
+++ b/d8_r8/main/settings.gradle.kts
@@ -0,0 +1,18 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+pluginManagement {
+ repositories {
+ gradlePluginPortal()
+ }
+}
+
+dependencyResolutionManagement {
+ repositories {
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+
+rootProject.name = "r8"
diff --git a/d8_r8/settings.gradle.kts b/d8_r8/settings.gradle.kts
new file mode 100644
index 0000000..2feb93c
--- /dev/null
+++ b/d8_r8/settings.gradle.kts
@@ -0,0 +1,30 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// TODO(X): Move this file out the repository root when old gradle is removed.
+
+pluginManagement {
+ repositories {
+ gradlePluginPortal()
+ }
+}
+
+dependencyResolutionManagement {
+ repositories {
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+
+rootProject.name = "d8-r8"
+
+// This project is temporarily located in d8_r8. When moved to root, the parent
+// folder should just be removed.
+includeBuild(rootProject.projectDir.parentFile.resolve("commonBuildSrc"))
+includeBuild("keepanno")
+
+// We need to include src/main as a composite-build otherwise our test-modules
+// will compete with the test to compile the source files.
+includeBuild("main")
+includeBuild("test")
diff --git a/d8_r8/test/build.gradle.kts b/d8_r8/test/build.gradle.kts
new file mode 100644
index 0000000..34f153b
--- /dev/null
+++ b/d8_r8/test/build.gradle.kts
@@ -0,0 +1,55 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+plugins {
+ `kotlin-dsl`
+ id("dependencies-plugin")
+}
+
+val root = getRoot();
+
+java {
+ sourceSets.test.configure {
+ java.srcDir(root.resolveAll("src", "test", "java"))
+ }
+ sourceCompatibility = JvmCompatibility.sourceCompatibility
+ targetCompatibility = JvmCompatibility.targetCompatibility
+}
+
+// We cannot use languageVersion.set(JavaLanguageVersion.of("8")) because gradle cannot figure
+// out that the jdk is 1_8 and will try to download it.
+tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
+ kotlinOptions {
+ jvmTarget = "11"
+ }
+}
+
+
+dependencies {
+ implementation(":r8")
+ implementation(":keepanno")
+ implementation(Deps.asm)
+ implementation(Deps.gson)
+ implementation(Deps.guava)
+ implementation(Deps.junit)
+ implementation(Deps.kotlinStdLib)
+ implementation(Deps.kotlinReflect)
+ implementation(Deps.kotlinMetadata)
+ implementation(files(root.resolveAll("third_party", "ddmlib", "ddmlib.jar")))
+ implementation(
+ files(
+ root.resolveAll("third_party", "jdwp-tests", "apache-harmony-jdwp-tests-host.jar")))
+ implementation(files(root.resolveAll("third_party", "jasmin", "jasmin-2.4.jar")))
+ implementation(Deps.fastUtil)
+ implementation(Deps.smali)
+ implementation(Deps.asmUtil)
+}
+
+tasks.named("test") {
+ dependsOn(gradle.includedBuild("tests_java_8").task(":compileJava"))
+}
+
+tasks.withType<Test> {
+ environment("USE_NEW_GRADLE_SETUP", "true")
+}
diff --git a/d8_r8/test/gradle.properties b/d8_r8/test/gradle.properties
new file mode 100644
index 0000000..ef0be28
--- /dev/null
+++ b/d8_r8/test/gradle.properties
@@ -0,0 +1,17 @@
+# Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8
+kotlin.daemon.jvmargs=-Xmx3g -Dkotlin.js.compiler.legacy.force_enabled=true
+systemProp.file.encoding=UTF-8
+
+# Enable new incremental compilation
+kotlin.incremental.useClasspathSnapshot=true
+
+org.gradle.parallel=true
+org.gradle.caching=true
+
+# Do not download any jdks or detect them. We provide them
+org.gradle.java.installations.auto-detect=false
+org.gradle.java.installations.auto-download=false
diff --git a/d8_r8/test/settings.gradle.kts b/d8_r8/test/settings.gradle.kts
new file mode 100644
index 0000000..3138d52
--- /dev/null
+++ b/d8_r8/test/settings.gradle.kts
@@ -0,0 +1,15 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+dependencyResolutionManagement {
+ repositories {
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+
+rootProject.name = "r8-tests"
+
+val root = rootProject.projectDir.parentFile
+includeBuild(root.resolve("test_modules").resolve("tests_java_8"))
diff --git a/d8_r8/test_modules/tests_java_8/build.gradle.kts b/d8_r8/test_modules/tests_java_8/build.gradle.kts
new file mode 100644
index 0000000..9908599
--- /dev/null
+++ b/d8_r8/test_modules/tests_java_8/build.gradle.kts
@@ -0,0 +1,88 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import org.gradle.api.JavaVersion
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
+plugins {
+ `kotlin-dsl`
+ `java-library`
+ id("dependencies-plugin")
+}
+
+val root = getRoot()
+
+java {
+ sourceSets.main.configure {
+ java.srcDir(root.resolveAll("src", "test", "java"))
+ }
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+}
+
+
+// We cannot use languageVersion.set(JavaLanguageVersion.of("8")) because gradle cannot figure
+// out that the jdk is 1_8 and will try to download it.
+tasks.withType<KotlinCompile> {
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
+}
+
+// The test module compilation depends on main and keep anno output, but we cannot directly
+// reference the task we only obtain a task reference. To obtain the actual reference by creating
+// a dummy.
+tasks.register("dummy-keepanno-reference") {
+ dependsOn(gradle.includedBuild("keepanno").task(":jar"))
+}
+val keepAnnoTask = tasks.getByName("dummy-keepanno-reference")
+ .taskDependencies
+ .getDependencies(tasks.getByName("dummy-keepanno-reference"))
+ .iterator()
+ .next()
+
+tasks.register("dummy-r8-reference") {
+ dependsOn(gradle.includedBuild("main").task(":jar"))
+}
+val r8Task = tasks.getByName("dummy-r8-reference")
+ .taskDependencies
+ .getDependencies(tasks.getByName("dummy-r8-reference"))
+ .iterator()
+ .next()
+
+dependencies {
+ implementation(keepAnnoTask.outputs.files)
+ implementation(r8Task.outputs.files)
+ implementation(Deps.asm)
+ implementation(Deps.gson)
+ implementation(Deps.guava)
+ implementation(Deps.junit)
+ implementation(Deps.kotlinStdLib)
+ implementation(Deps.kotlinReflect)
+ implementation(Deps.kotlinMetadata)
+ implementation(files(root.resolveAll("third_party", "ddmlib", "ddmlib.jar")))
+ implementation(
+ files(
+ root.resolveAll("third_party", "jdwp-tests", "apache-harmony-jdwp-tests-host.jar")))
+ implementation(files(root.resolveAll("third_party", "jasmin", "jasmin-2.4.jar")))
+ implementation(Deps.fastUtil)
+ implementation(Deps.smali)
+ implementation(Deps.asmUtil)
+}
+
+tasks.withType<JavaCompile> {
+ dependsOn(keepAnnoTask)
+ dependsOn(r8Task)
+ options.setFork(true)
+ options.forkOptions.memoryMaximumSize = "3g"
+ options.forkOptions.jvmArgs = listOf(
+ "-Xss256m",
+ // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
+ "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar")
+}
+
+tasks.withType<KotlinCompile> {
+ dependsOn(keepAnnoTask)
+ dependsOn(r8Task)
+}
diff --git a/d8_r8/test_modules/tests_java_8/gradle.properties b/d8_r8/test_modules/tests_java_8/gradle.properties
new file mode 100644
index 0000000..ef0be28
--- /dev/null
+++ b/d8_r8/test_modules/tests_java_8/gradle.properties
@@ -0,0 +1,17 @@
+# Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8
+kotlin.daemon.jvmargs=-Xmx3g -Dkotlin.js.compiler.legacy.force_enabled=true
+systemProp.file.encoding=UTF-8
+
+# Enable new incremental compilation
+kotlin.incremental.useClasspathSnapshot=true
+
+org.gradle.parallel=true
+org.gradle.caching=true
+
+# Do not download any jdks or detect them. We provide them
+org.gradle.java.installations.auto-detect=false
+org.gradle.java.installations.auto-download=false
diff --git a/d8_r8/test_modules/tests_java_8/settings.gradle.kts b/d8_r8/test_modules/tests_java_8/settings.gradle.kts
new file mode 100644
index 0000000..290b820
--- /dev/null
+++ b/d8_r8/test_modules/tests_java_8/settings.gradle.kts
@@ -0,0 +1,28 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+pluginManagement {
+ repositories {
+ gradlePluginPortal()
+ }
+}
+
+dependencyResolutionManagement {
+ repositories {
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+
+rootProject.name = "r8-java8-tests"
+
+val d8Root = rootProject.projectDir.parentFile.parentFile
+val root = d8Root.parentFile
+
+includeBuild(root.resolve("commonBuildSrc"))
+includeBuild(d8Root.resolve("keepanno"))
+
+// We need to include src/main as a composite-build otherwise our test-modules
+// will compete with the test to compile the source files.
+includeBuild(d8Root.resolve("main"))