Skip to content

Commit

Permalink
Merge pull request #20 from jvican/main
Browse files Browse the repository at this point in the history
Support mainClass in Gradle 8.0.1
  • Loading branch information
ckipp01 authored Mar 2, 2023
2 parents e0f2f5e + a1e167d commit 466b044
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -221,7 +229,6 @@ abstract class ConfigGenerationSuite extends BaseConfigSuite {
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.getRoot)
.withPluginClasspath(getClasspath)
.forwardOutput()
.withArguments("bloopInstall", "-Si")
.build()

Expand Down Expand Up @@ -1470,7 +1477,6 @@ abstract class ConfigGenerationSuite extends BaseConfigSuite {
.withProjectDir(buildDirMain)
.withPluginClasspath(getClasspath)
.withArguments("bloopInstall", "-Si")
.forwardOutput()
.build()

val projectName = testProjectDir.getRoot.getName
Expand Down

0 comments on commit 466b044

Please sign in to comment.