Skip to content

Commit

Permalink
Implement AppStartPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Sep 10, 2023
1 parent 4d98a28 commit 571815b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
17 changes: 17 additions & 0 deletions build-logic/app-start-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.7.10'
id 'org.gradle.kotlin.kotlin-dsl' version '2.4.1'
}

repositories {
mavenCentral()
}

gradlePlugin {
plugins {
simplePlugin {
id = 'bisq.gradle.app_start_plugin.AppStartPlugin'
implementationClass = 'bisq.gradle.app_start_plugin.AppStartPlugin'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package bisq.gradle.app_start_plugin

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaApplication
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.Sync
import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.toolchain.*
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.register
import java.io.File
import javax.inject.Inject

class AppStartPlugin @Inject constructor(private val javaToolchainService: JavaToolchainService) : Plugin<Project> {

override fun apply(project: Project) {
val installDistTask: TaskProvider<Sync> = project.tasks.named("installDist", Sync::class.java)

val javaApplicationExtension = project.extensions.findByType<JavaApplication>()
checkNotNull(javaApplicationExtension) { "Can't find JavaApplication extension." }

project.tasks.register<JavaExec>("startBisqApp") {
dependsOn(installDistTask)
javaLauncher.set(getJavaLauncher(project))

classpath = installDistTask.map {
val appLibsDir = File(it.destinationDir, "lib")
val allFiles = appLibsDir.listFiles()
project.files(allFiles)
}.get()

jvmArgs.addAll(javaApplicationExtension.applicationDefaultJvmArgs)

workingDir = project.projectDir.parentFile
mainClass.set(javaApplicationExtension.mainClass)
}
}

private fun getJavaLauncher(project: Project): Provider<JavaLauncher> {
val javaExtension = project.extensions.findByType<JavaPluginExtension>()
checkNotNull(javaExtension) { "Can't find JavaPluginExtension extension." }

val toolchain = javaExtension.toolchain
return javaToolchainService.launcherFor(toolchain)
}
}
1 change: 1 addition & 0 deletions build-logic/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencyResolutionManagement {
}
}

include 'app-start-plugin'
include 'commons'
include 'gradle-tasks'
include 'packaging'
Expand Down

0 comments on commit 571815b

Please sign in to comment.