diff --git a/README.md b/README.md index 3b1f9b9..ab82c29 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ You can also restart the wildfly after the deployment (and await it), analogous ```kotlin reload = false // default for reload is true, so deactivate it first restart = true - awaitRestart = true + awaitRestart = true ``` You can also deploy to WildFly in domain mode, but only one server group per task @@ -108,14 +108,14 @@ task deployDomain(type: DeployWildflyTask) { user = deploy.user password = deploy.password deploymentName = project.name - runtimeName = "${project.name}-${project.version}.war" - file = "$buildDir/libs/${project.name}-${project.version}.war" + runtimeName = tasks.war.archiveFileName + file = tasks.war.archiveFile // redeploy if artifact with same name already deployed undeployBeforehand = true // server group of domain mode domainServerGroup = "main-server-group" // ask to restart servers after deploy instead of only reload them - restart = true + restart = true reload = false } ``` @@ -148,10 +148,10 @@ task("deploy", DeployWildflyTask::class) { port = 9090 user = "mgmt_user" password = "mgmt_password" - deploymentName = project.name //cli: --name=$runtimeName - runtimeName = "${project.name}-$version.war" //cli: --runtime-name=$runtimeName - // filepath, here a war example - file = "$buildDir/libs/${project.name}-$version.war".apply { println("file=$this") } + deploymentName.set(project.name) //cli: --name=$runtimeName + runtimeName.set(tasks.war.get().archiveFileName) //cli: --runtime-name=$runtimeName + // Using war.archiveFile will make the deploy task depend on the war task implicitly, no need for dependsOn("war") + file.set(tasks.war.get().archiveFile) } ``` @@ -195,7 +195,7 @@ $ ./gradlew clean build publish This will deploy the locally build plugin jar into your local maven repo and also into `build/lib`. -To use your locally build plugin you can just +To use your locally build plugin you can just [override the plugin resolutionStrategy](https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_resolution_rules) inside your settings.gradle(.kts) file. @@ -229,7 +229,7 @@ pluginManagement { repositories { maven { // this is the build folder of your local wildfly-deploy-gradle-plugin repository, you might need to adapt this - url = uri("build/lib") + url = uri("build/lib") } // or mavenLocal() @@ -239,4 +239,3 @@ pluginManagement { } } ``` - diff --git a/integration/build.gradle.kts b/integration/build.gradle.kts index 96488f2..a2f1330 100644 --- a/integration/build.gradle.kts +++ b/integration/build.gradle.kts @@ -7,7 +7,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "1.3.21" - id("com.mkring.wildlydeplyplugin.deploy-wildfly-plugin") version "0.2.10" + id("com.mkring.wildlydeplyplugin.deploy-wildfly-plugin") version "0.2.12" war } buildscript { @@ -64,14 +64,15 @@ task("deploy", DeployWildflyTask::class) { port = 9990 user = "mgmt" password = "1234" - deploymentName = project.name - runtimeName = "${project.name}-$version.war" - file = "$buildDir/libs/${project.name}-$version.war".apply { println("file=$this") } + deploymentName.set(project.name) + runtimeName.set(tasks.war.get().archiveFileName) + // Using war.archiveFile will make the deploy task depend on the war task implicitly + file.set(tasks.war.get().archiveFile) reload = false - dependsOn("build-id", "build", "war") } tasks.war { + dependsOn("build-id") webInf { from("build.id") } -} \ No newline at end of file +} diff --git a/integration/settings.gradle.kts b/integration/settings.gradle.kts index 966232f..c0d9a90 100644 --- a/integration/settings.gradle.kts +++ b/integration/settings.gradle.kts @@ -3,7 +3,7 @@ pluginManagement { resolutionStrategy { eachPlugin { if (requested.id.namespace == "com.mkring.wildlydeplyplugin") { - useModule("com.mkring.wildlydeplyplugin:wildfly-deploy-gradle-plugin:0.2.10") + useModule("com.mkring.wildlydeplyplugin:wildfly-deploy-gradle-plugin:0.2.12") } } } @@ -11,4 +11,4 @@ pluginManagement { mavenLocal() gradlePluginPortal() } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/mkring/wildlydeplyplugin/DeployWildflyPlugin.kt b/src/main/kotlin/com/mkring/wildlydeplyplugin/DeployWildflyPlugin.kt index 3f56db8..2e4f420 100644 --- a/src/main/kotlin/com/mkring/wildlydeplyplugin/DeployWildflyPlugin.kt +++ b/src/main/kotlin/com/mkring/wildlydeplyplugin/DeployWildflyPlugin.kt @@ -3,7 +3,10 @@ package com.mkring.wildlydeplyplugin import org.gradle.api.DefaultTask import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.TaskAction import org.slf4j.LoggerFactory @@ -17,16 +20,17 @@ open class DeployWildflyPlugin : Plugin { open class DeployWildflyTask : DefaultTask() { val log = LoggerFactory.getLogger(DeployWildflyTask::class.java) - @Input - var file: String? = null + @InputFile + val file: RegularFileProperty = project.objects.fileProperty() @Input var domainServerGroup: String = "" @Input - var deploymentName: String? = null + val deploymentName: Property = project.objects.property(String::class.java) + @Input - var runtimeName: String? = null + val runtimeName: Property = project.objects.property(String::class.java) @Input var host: String = "localhost" @@ -56,13 +60,12 @@ open class DeployWildflyTask : DefaultTask() { init { group = "help" description = "Deploys files to a Wildfly und reloads it afterwards" - dependsOn("build") outputs.upToDateWhen { false } } @TaskAction fun deployWildfly() { - if (file == null || user == null || password == null) { + if (file.get().asFile.name.isEmpty() || user == null || password == null) { log.error("DeployWildflyTask: missing configuration") return } @@ -80,18 +83,18 @@ open class DeployWildflyTask : DefaultTask() { if (awaitRestart && restart.not()) { log.warn("awaitRestart is pointless if no restart is set") } - log.info("deployWildfly: going to deploy $file to $host:$port") + log.info("deployWildfly: going to deploy ${file.get().asFile} to $host:$port") try { FileDeployer( - file, + file.get().asFile, host, port, user, password, reload, force, - deploymentName, - runtimeName, + deploymentName.get(), + runtimeName.get(), domainServerGroup, awaitReload, undeployBeforehand, diff --git a/src/main/kotlin/com/mkring/wildlydeplyplugin/ExecuteWildflyTask.kt b/src/main/kotlin/com/mkring/wildlydeplyplugin/ExecuteWildflyTask.kt index 21b75d7..3e00e7d 100644 --- a/src/main/kotlin/com/mkring/wildlydeplyplugin/ExecuteWildflyTask.kt +++ b/src/main/kotlin/com/mkring/wildlydeplyplugin/ExecuteWildflyTask.kt @@ -21,7 +21,6 @@ open class ExecuteWildflyTask : DefaultTask() { init { group = "help" description = "Executes cli commands on a Wildfly" - dependsOn("build") outputs.upToDateWhen { false } } @@ -42,4 +41,4 @@ open class ExecuteWildflyTask : DefaultTask() { throw e } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/mkring/wildlydeplyplugin/FileDeployer.kt b/src/main/kotlin/com/mkring/wildlydeplyplugin/FileDeployer.kt index 80665fd..5d6eef5 100644 --- a/src/main/kotlin/com/mkring/wildlydeplyplugin/FileDeployer.kt +++ b/src/main/kotlin/com/mkring/wildlydeplyplugin/FileDeployer.kt @@ -14,7 +14,7 @@ import java.time.temporal.ChronoUnit private val log = LoggerFactory.getLogger(FileDeployer::class.java) class FileDeployer( - private val file: String?, + private val file: File, private val host: String, private val port: Int, private val user: String?, @@ -82,7 +82,7 @@ class FileDeployer( "" } - val deploymentExists = File(file).isFile + val deploymentExists = file.isFile log.debug("given $file existent: $deploymentExists") if (deploymentExists.not()) throw IllegalStateException("couldn't find given deployment")