From a1e167d13975ecbedf84a604778058df470537ff Mon Sep 17 00:00:00 2001 From: Jorge Vicente Cantero Date: Tue, 28 Feb 2023 12:57:17 -0800 Subject: [PATCH] Add support for Gradle 8.0.1 --- .../gradle/model/BloopConverter.scala | 15 ++++++++++++++- .../gradle/ConfigGenerationSuite.scala | 12 +++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/scala/bloop/integrations/gradle/model/BloopConverter.scala b/src/main/scala/bloop/integrations/gradle/model/BloopConverter.scala index 6f418d58..e4fc2b34 100644 --- a/src/main/scala/bloop/integrations/gradle/model/BloopConverter.scala +++ b/src/main/scala/bloop/integrations/gradle/model/BloopConverter.scala @@ -47,6 +47,8 @@ import org.gradle.api.file.RegularFileProperty import org.gradle.api.internal.file.copy.DefaultCopySpec import org.gradle.api.internal.tasks.compile.DefaultJavaCompileSpec import org.gradle.api.internal.tasks.compile.JavaCompilerArgumentsBuilder +import org.gradle.api.plugins.JavaApplication +import org.gradle.api.provider.Property import org.gradle.api.provider.Provider import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.bundling.AbstractArchiveTask @@ -789,7 +791,7 @@ class BloopConverter(parameters: BloopParameters) { val mainClass = if (testTask.isEmpty) - project.javaApplicationExt.flatMap(f => Option(f.getMainClassName)) + project.javaApplicationExt.flatMap(getJavaMainClass) else None @@ -1109,6 +1111,17 @@ class BloopConverter(parameters: BloopParameters) { } } + private def getJavaMainClass(app: JavaApplication): Option[String] = + try Option(app.getMainClassName()) + catch { + case _: NoSuchMethodError => + // Gradle 8.0.1 removed `mainClassName` in favor of `mainClass` + // https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/JavaApplication.html#getMainClass-- + val mainClassNameHandle = + classOf[JavaApplication].getDeclaredMethod("getMainClass") + Option(mainClassNameHandle.invoke(app).asInstanceOf[Property[String]].getOrNull()) + } + private def getPluginsAsOptions(scalaCompile: ScalaCompile): List[String] = { // Gradle 6.4 has scalaCompilerPlugins option try { diff --git a/src/test/scala/bloop/integrations/gradle/ConfigGenerationSuite.scala b/src/test/scala/bloop/integrations/gradle/ConfigGenerationSuite.scala index a31ade44..ce136487 100644 --- a/src/test/scala/bloop/integrations/gradle/ConfigGenerationSuite.scala +++ b/src/test/scala/bloop/integrations/gradle/ConfigGenerationSuite.scala @@ -46,10 +46,18 @@ class ConfigGenerationSuite_Android_Scala_plugin extends ConfigGenerationSuite { } */ +class ConfigGenerationSuite_8 extends ConfigGenerationSuite { + protected val gradleVersion: String = "8.0.1" + protected val supportsCurrentJavaVersion: Boolean = true + // TODO: Enable Android support for Gradle versions higher than 8.0.1 in the future + override protected val supportsAndroid: Boolean = false +} + abstract class ConfigGenerationSuite extends BaseConfigSuite { protected val gradleVersion: String protected val supportsCurrentJavaVersion: Boolean - private def supportsAndroid: Boolean = gradleVersion >= "6.1.1" + protected def supportsAndroid: Boolean = gradleVersion >= "6.1.1" + // private def supportsAndroidScalaPlugin: Boolean = gradleVersion == "6.6" private def supportsScala3: Boolean = gradleVersion >= "7.3" private def canConsumeTestRuntime: Boolean = gradleVersion < "7.0" @@ -221,7 +229,6 @@ abstract class ConfigGenerationSuite extends BaseConfigSuite { .withGradleVersion(gradleVersion) .withProjectDir(testProjectDir.getRoot) .withPluginClasspath(getClasspath) - .forwardOutput() .withArguments("bloopInstall", "-Si") .build() @@ -1470,7 +1477,6 @@ abstract class ConfigGenerationSuite extends BaseConfigSuite { .withProjectDir(buildDirMain) .withPluginClasspath(getClasspath) .withArguments("bloopInstall", "-Si") - .forwardOutput() .build() val projectName = testProjectDir.getRoot.getName