Moved deploy configuration to afterEvaluate

This commit is contained in:
Alexander Nozik 2019-07-07 14:23:10 +03:00
parent cd9bf6adc2
commit 404bcfd28a
2 changed files with 88 additions and 84 deletions

View File

@ -8,7 +8,7 @@ plugins {
} }
group = "scientifik" group = "scientifik"
version = "0.1.0" version = "0.1.1"
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()

View File

@ -38,54 +38,57 @@ open class ScientifikPublishPlugin : Plugin<Project> {
project.plugins.apply("maven-publish") project.plugins.apply("maven-publish")
val extension = project.extensions.create<ScientifikExtension>("scientifik") val extension = project.extensions.create<ScientifikExtension>("scientifik")
val bintrayRepo = project.bintrayRepo project.afterEvaluate {
val vcs = project.vcs
if (bintrayRepo == null || vcs == null) { val bintrayRepo = project.bintrayRepo
project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.") val vcs = project.vcs
}
project.configure<PublishingExtension> { if (bintrayRepo == null || vcs == null) {
repositories { project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.")
maven("https://bintray.com/mipt-npm/$bintrayRepo") return@afterEvaluate
} }
// Process each publication we have in this project project.configure<PublishingExtension> {
publications.filterIsInstance<MavenPublication>().forEach { publication -> repositories {
maven("https://bintray.com/mipt-npm/$bintrayRepo")
}
@Suppress("UnstableApiUsage") // Process each publication we have in this project
publication.pom { publications.filterIsInstance<MavenPublication>().forEach { publication ->
name.set(project.name)
description.set(project.description)
url.set(vcs)
licenses { @Suppress("UnstableApiUsage")
license { publication.pom {
name.set("The Apache Software License, Version 2.0") name.set(project.name)
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") description.set(project.description)
distribution.set("repo")
}
}
developers {
developer {
id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT")
organizationUrl.set("http://npm.mipt.ru")
}
}
scm {
url.set(vcs) url.set(vcs)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT")
organizationUrl.set("http://npm.mipt.ru")
}
}
scm {
url.set(vcs)
}
} }
} }
} }
}
if (extension.kdoc) { if (extension.kdoc) {
project.plugins.apply("org.jetbrains.dokka") project.plugins.apply("org.jetbrains.dokka")
project.afterEvaluate {
extensions.findByType<KotlinMultiplatformExtension>()?.apply { extensions.findByType<KotlinMultiplatformExtension>()?.apply {
val dokka by tasks.getting(DokkaTask::class) { val dokka by tasks.getting(DokkaTask::class) {
outputFormat = "html" outputFormat = "html"
@ -165,69 +168,70 @@ open class ScientifikPublishPlugin : Plugin<Project> {
} }
} }
} }
} }
}
project.plugins.apply("com.jfrog.bintray") project.plugins.apply("com.jfrog.bintray")
project.configure<BintrayExtension> { project.configure<BintrayExtension> {
user = project.findProperty("bintrayUser") as? String ?: System.getenv("BINTRAY_USER") user = project.findProperty("bintrayUser") as? String ?: System.getenv("BINTRAY_USER")
key = project.findProperty("bintrayApiKey") as? String? ?: System.getenv("BINTRAY_API_KEY") key = project.findProperty("bintrayApiKey") as? String? ?: System.getenv("BINTRAY_API_KEY")
publish = true publish = true
override = true // for multi-platform Kotlin/Native publishing override = true // for multi-platform Kotlin/Native publishing
// We have to use delegateClosureOf because bintray supports only dynamic groovy syntax // We have to use delegateClosureOf because bintray supports only dynamic groovy syntax
// this is a problem of this plugin // this is a problem of this plugin
pkg.apply { pkg.apply {
userOrg = "mipt-npm" userOrg = "mipt-npm"
repo = bintrayRepo repo = bintrayRepo
name = project.name name = project.name
issueTrackerUrl = "${vcs}/issues" issueTrackerUrl = "${vcs}/issues"
setLicenses("Apache-2.0") setLicenses("Apache-2.0")
vcsUrl = vcs vcsUrl = vcs
version.apply { version.apply {
name = project.version.toString() name = project.version.toString()
vcsTag = project.version.toString() vcsTag = project.version.toString()
released = java.util.Date().toString() released = java.util.Date().toString()
}
} }
}
//workaround bintray bug //workaround bintray bug
project.afterEvaluate {
setPublications(*project.extensions.findByType<PublishingExtension>()!!.publications.names.toTypedArray()) setPublications(*project.extensions.findByType<PublishingExtension>()!!.publications.names.toTypedArray())
}
// project.tasks.figetByPath("bintrayUpload") { // project.tasks.figetByPath("bintrayUpload") {
// dependsOn(publishToMavenLocal) // dependsOn(publishToMavenLocal)
// } // }
} }
project.plugins.apply("com.jfrog.artifactory") project.plugins.apply("com.jfrog.artifactory")
project.configure<ArtifactoryPluginConvention> { project.configure<ArtifactoryPluginConvention> {
val artifactoryUser: String? by project val artifactoryUser: String? by project
val artifactoryPassword: String? by project val artifactoryPassword: String? by project
val artifactoryContextUrl = "http://npm.mipt.ru:8081/artifactory" val artifactoryContextUrl = "http://npm.mipt.ru:8081/artifactory"
setContextUrl(artifactoryContextUrl)//The base Artifactory URL if not overridden by the publisher/resolver setContextUrl(artifactoryContextUrl)//The base Artifactory URL if not overridden by the publisher/resolver
publish(delegateClosureOf<PublisherConfig> { publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<GroovyObject> { repository(delegateClosureOf<GroovyObject> {
setProperty("repoKey", "gradle-dev-local") setProperty("repoKey", "gradle-dev-local")
setProperty("username", artifactoryUser) setProperty("username", artifactoryUser)
setProperty("password", artifactoryPassword) setProperty("password", artifactoryPassword)
})
defaults(delegateClosureOf<GroovyObject> {
invokeMethod("publications", arrayOf("jvm", "js", "kotlinMultiplatform", "metadata"))
})
}) })
resolve(delegateClosureOf<ResolverConfig> {
defaults(delegateClosureOf<GroovyObject> { repository(delegateClosureOf<GroovyObject> {
invokeMethod("publications", arrayOf("jvm", "js", "kotlinMultiplatform", "metadata")) setProperty("repoKey", "gradle-dev")
setProperty("username", artifactoryUser)
setProperty("password", artifactoryPassword)
})
}) })
}) }
resolve(delegateClosureOf<ResolverConfig> {
repository(delegateClosureOf<GroovyObject> {
setProperty("repoKey", "gradle-dev")
setProperty("username", artifactoryUser)
setProperty("password", artifactoryPassword)
})
})
} }
} }
} }