gradle / gradle/playframework

Supporting multiple main classes for tooling and commands

Open
#100 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
47
Forks
41
PR merge metrics
No merged PRs in 30d

Description

I used `sbt` and SBT native packager in the past. Native packager will generate a start script for each discovered main class found on the classpath. I have a Play Framework application with a few commands written for tooling. I'm trying to figure out the best solution to support these commands along in my gradle build, and how to create a startscript for those commands.

Up until now I'm trying out a very hacky solution in my `build.gradle.kts`:

```
// Generate tasks for each command we have
File("${project.projectDir}/app/biz/companyname/command")
.listFiles({ _, name -> Regex(".+Command\\.scala") matches name })
.forEach { file ->
val commandClassName = file.nameWithoutExtension

// Task to run the command from Gradle
tasks.create(commandClassName.toLowerDashCase()) {
group = "commands"
description = "Run $commandClassName"
main = "biz.companyname.command.$commandClassName"
classpath = sourceSets["main"].runtimeClasspath + files("$buildDir/playBinary/lib/projectname.jar")
dependsOn("compilePlayBinaryScala")
}

// Task to create the start script for the command
val startScript = tasks.create("createStartScripts$commandClassName") {
group = "startscripts"
description = "Generates the startscript for $commandClassName"
applicationName = commandClassName.toLowerDashCase()
mainClassName = "biz.companyname.command.$commandClassName"
classpath = files("$buildDir/stage/playBinary/lib/projectname.jar")
outputDir = file("$buildDir/stage/playBinary/bin")
dependsOn("createPlayBinaryStartScripts")
}
}
```

I have a hard time figuring out the classpath of the Play project. I also cannot seem to find a good way to automatically hook in the Play Framework tasks.

Are there other suggestions or recommended ways of doing this in a cleaner way? I actually want to be able to run the command via a gradle task, and in my production build run the commands as start scripts

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.