Could not PUT https://oss.sonatype.org/service/local/staging/deploy/maven2/bom-plugin/ - gradle

I'm trying to publish my first Gradle plugin to maven central (sonatype), but I'm receiving the following error:
Execution failed for task ':publishBom-pluginPluginMarkerMavenPublicationToMavenRepository'.
> Failed to publish publication 'bom-pluginPluginMarkerMaven' to repository 'maven'
> Could not PUT 'https://oss.sonatype.org/service/local/staging/deploy/maven2/bom-plugin/bom-plugin.gradle.plugin/0.3/bom-plugin.gradle.plugin-0.3.pom'.
Received status code 400 from server: Bad Request
It seems that for some reason, the publishing task is trying to publish my plugin at the root of the sonatype repository, it works when I do execute the task publishToMavenLocal, however, published this strange file in my m2 local: /.m2/repository/bom-plugin/bom-plugin.gradle.plugin and also publish the plugin here /.m2/repository/dev/thiagosouto/bom-plugin/0.3/
I think this is causing the issue but I don't have any clue to solve this problem.
My build.gradle.kts file
plugins {
java
`java-gradle-plugin`
`kotlin-dsl`
`maven-publish`
signing
kotlin("jvm") version "1.4.31"
id("com.gradle.plugin-publish") version "0.13.0"
}
group "dev.thiagosouto"
version "0.3"
buildscript {
repositories {
mavenCentral()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
}
gradlePlugin {
plugins {
create("bom-plugin") {
id = "bom-plugin"
implementationClass = "dev.thiagosouto.plugins.bom.BomPlugin"
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("com.squareup:kotlinpoet:1.7.2")
testImplementation("com.google.truth:truth:1.1.2")
testImplementation("junit:junit:4.13.2")
testImplementation("dev.thiagosouto:file-butler:0.3.0")
}
sourceSets.main {
java.srcDirs("src/main/kotlin")
}
sourceSets.test {
java.srcDirs("src/test/kotlin")
}
tasks.withType<GenerateModuleMetadata> {
enabled = false
}
publishing {
val ossrhUsername: String by project
val ossrhPassword: String by project
repositories {
maven(url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
publications {
group = "dev.thiagosouto"
version = "0.3"
create<MavenPublication>("mavenJava") {
pom {
name.set("bom-plugin")
description.set("A library to help apply tdd through help functions");
url.set("https://thiagosouto.dev")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
scm {
connection.set("scm:git:git://github.com/othiagosouto/bom-plugin.git/")
developerConnection.set("scm:git:ssh://github.com:othiagosouto/bom-plugin.git")
url.set("https://github.com/othiagosouto/bom-plugin")
}
developers {
developer {
id.set("othiagosouto")
name.set("Thiago Souto silva de barros Santos")
email.set("soutosss#gmail.com")
}
}
}
}
}
}
afterEvaluate {
signing {
sign(publishing.publications["mavenJava"])
}
}

Related

Kotlin multiplatform publish with dokka and sources

I am struggling to publish a Kotlin multiplatform project properly to maven (for now mavenLocal). I can add the dependency to another multiplatform project and use the code but I don't get any documentation and I am not sure if I am doing something wrong or if that is simply not possible at the moment.
From what I understand you cannot use the normal javadoc because it is bound to Java which does not make sense in a multiplatform environment. I read somewhere that in that case you should use the html version of dokka. I can see that I get a "javadoc.jar" with content to my mavenLocal but still in the IDE in an example project where I add my KMP library as a dependency, I don't see any documentation.
Also, the code decompiling seems to be weird. I guess somehow the sources are also not properly resolved.
According to the documentation everything should automatically and perfectly work by simply adding the maven-publish and the dokka plugin. But it seems like this is not the case and actually nothing is working as I'd expect it :D
Does anyone know, how to properly set that up?
My gradle file looks like this:
plugins {
kotlin("multiplatform") version "1.6.21"
id("org.jetbrains.kotlinx.benchmark") version "0.4.2"
id("org.jetbrains.dokka") version "1.6.21"
`maven-publish`
signing
}
group = "io.github.quillraven.fleks"
version = "1.4-KMP-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
kotlin {
targets {
jvm {
compilations {
all {
kotlinOptions {
jvmTarget = "1.8"
}
}
val main by getting { }
// custom benchmark compilation
val benchmarks by compilations.creating {
defaultSourceSet {
dependencies {
// Compile against the main compilation's compile classpath and outputs:
implementation(main.compileDependencyFiles + main.output.classesDirs)
}
}
}
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
}
js(BOTH) {
browser { }
}
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
sourceSets {
val commonMain by getting { }
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jvmBenchmarks by getting {
dependsOn(commonMain)
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.2")
implementation("com.badlogicgames.ashley:ashley:1.7.4")
implementation("net.onedaybeard.artemis:artemis-odb:2.3.0")
}
}
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
}
benchmark {
targets {
register("jvmBenchmarks")
}
}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
from(tasks.dokkaHtml)
}
publishing {
repositories {
maven {
url = if (project.version.toString().endsWith("SNAPSHOT")) {
uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
} else {
uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
}
credentials {
username = System.getenv("OSSRH_USERNAME")
password = System.getenv("OSSRH_TOKEN")
}
}
}
publications {
val kotlinMultiplatform by getting(MavenPublication::class) {
version = project.version.toString()
groupId = project.group.toString()
artifactId = "Fleks"
artifact(javadocJar)
pom {
name.set("Fleks")
description.set("A lightweight entity component system written in Kotlin.")
url.set("https://github.com/Quillraven/Fleks")
scm {
connection.set("scm:git:git#github.com:quillraven/fleks.git")
developerConnection.set("scm:git:git#github.com:quillraven/fleks.git")
url.set("https://github.com/quillraven/fleks/")
}
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
id.set("Quillraven")
name.set("Simon Klausner")
email.set("quillraven#gmail.com")
}
}
}
}
signing {
useInMemoryPgpKeys(System.getenv("SIGNING_KEY"), System.getenv("SIGNING_PASSWORD"))
sign(kotlinMultiplatform)
}
}
}
// only sign if version is not a SNAPSHOT release.
// this makes it easier to publish to mavenLocal and test the packed version.
tasks.withType<Sign>().configureEach {
onlyIf { !project.version.toString().endsWith("SNAPSHOT") }
}
When I run the publishToMavenLocal gradle task then I get following directories in my .m2 folder:
When I then create an example project and add it as a dependency, then I don't see any quick documentation and also the decompiling is not working properly:
I was finally able to publish to mavenCentral. Not sure if this is the best way and correct way to do it, but it seems to work. Here is my build.gradle.kts. The important part is in the publications sections. For whatever reason it is not sufficient to have the "root" folder setup properly. I also had to adjust the pom, javadoc and signing of every single publication, too.
#file:Suppress("UNUSED_VARIABLE")
plugins {
kotlin("multiplatform") version "1.6.21"
id("org.jetbrains.kotlinx.benchmark") version "0.4.2"
id("org.jetbrains.dokka") version "1.6.21"
`maven-publish`
signing
}
group = "io.github.quillraven.fleks"
version = "1.4-KMP-RC1"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
kotlin {
targets {
jvm {
compilations {
all {
kotlinOptions {
jvmTarget = "1.8"
}
}
val main by getting { }
// custom benchmark compilation
val benchmarks by compilations.creating {
defaultSourceSet {
dependencies {
// Compile against the main compilation's compile classpath and outputs:
implementation(main.compileDependencyFiles + main.output.classesDirs)
}
}
}
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
}
js(BOTH) {
browser { }
}
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
sourceSets {
val commonMain by getting { }
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jvmBenchmarks by getting {
dependsOn(commonMain)
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.2")
implementation("com.badlogicgames.ashley:ashley:1.7.4")
implementation("net.onedaybeard.artemis:artemis-odb:2.3.0")
}
}
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
}
benchmark {
targets {
register("jvmBenchmarks")
}
}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
from(tasks.dokkaHtml)
}
publishing {
repositories {
maven {
url = if (project.version.toString().endsWith("SNAPSHOT")) {
uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
} else {
uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
}
credentials {
username = System.getenv("OSSRH_USERNAME")
password = System.getenv("OSSRH_TOKEN")
}
}
}
publications {
val kotlinMultiplatform by getting(MavenPublication::class) {
// we need to keep this block up here because
// otherwise the different target folders like js/jvm/native are not created
version = project.version.toString()
groupId = project.group.toString()
artifactId = "Fleks"
}
}
publications.forEach {
if (it !is MavenPublication) {
return#forEach
}
// We need to add the javadocJar to every publication
// because otherwise maven is complaining.
// It is not sufficient to only have it in the "root" folder.
it.artifact(javadocJar)
// pom information needs to be specified per publication
// because otherwise maven will complain again that
// information like license, developer or url are missing.
it.pom {
name.set("Fleks")
description.set("A lightweight entity component system written in Kotlin.")
url.set("https://github.com/Quillraven/Fleks")
scm {
connection.set("scm:git:git#github.com:quillraven/fleks.git")
developerConnection.set("scm:git:git#github.com:quillraven/fleks.git")
url.set("https://github.com/quillraven/fleks/")
}
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
id.set("Quillraven")
name.set("Simon Klausner")
email.set("quillraven#gmail.com")
}
}
}
signing {
useInMemoryPgpKeys(System.getenv("SIGNING_KEY"), System.getenv("SIGNING_PASSWORD"))
sign(it)
}
}
}
// only sign if version is not a SNAPSHOT release.
// this makes it easier to publish to mavenLocal and test the packed version.
tasks.withType<Sign>().configureEach {
onlyIf { !project.version.toString().endsWith("SNAPSHOT") }
}
Here is my example gradle file that publishes a kotlin multiplatform project with sources and javadocs to a maven repository.
The project source is here: https://github.com/danbrough/misc_demos/tree/master/kotlin_multiplatform_dokka
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("multiplatform")
id("org.jetbrains.dokka")
id("com.android.library")
`maven-publish`
}
group = "dokka.test"
version = "0.0.1"
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
repositories {
mavenCentral()
google()
}
kotlin {
jvm()
android()
linuxX64()
macosX64()
sourceSets {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
}
val posixMain by sourceSets.creating {}
targets.withType<KotlinNativeTarget>() {
compilations["main"].defaultSourceSet.dependsOn(posixMain)
}
}
tasks.withType<AbstractTestTask>() {
testLogging {
events = setOf(
TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED
)
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
showStackTraces = true
}
outputs.upToDateWhen {
false
}
}
tasks.withType(KotlinCompile::class) {
kotlinOptions {
jvmTarget = "11"
}
}
tasks.dokkaHtml.configure {
outputDirectory.set(buildDir.resolve("dokka"))
}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
from(tasks.dokkaHtml)
}
publishing {
repositories {
maven(project.buildDir.resolve("m2").toURI()) {
name = "m2"
}
}
publications.forEach {
if (it !is MavenPublication) {
return#forEach
}
it.artifact(javadocJar)
}
}
android {
compileSdk = 33
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
namespace = project.group.toString()
defaultConfig {
minSdk = 23
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
signingConfigs.register("release") {
storeFile = File(System.getProperty("user.home"), ".android/keystore")
keyAlias = "keyAlias"
storePassword = System.getenv("KEYSTORE_PASSWORD") ?: ""
keyPassword = System.getenv("KEYSTORE_PASSWORD") ?: ""
}
lint {
abortOnError = false
}
buildTypes {
getByName("debug") {
//debuggable(true)
}
getByName("release") {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
}
}
}

Signing fails when trying to publish to Maven Central using Sonatype nexus (gradle-nexus.publish-plugin)

I'm trying to publish my library to Maven Central. I already set it up over at Sonatype Nexus, and now I'm trying to hook up Gradle to it (this library depends on Minecraft Forge, so using Maven isn't an option).
I saw that there was a plugin created called Gradle Nexus Publish Plugin and thought I could use it to make publishing easier.
Using the publishAllPublicationsToSonatypeRepository Gradle task, I could publish a repo to Nexus;
But once I call closeSonatypeStagingRepository, it fails with the following error:
Execution failed for task ':signMavenPublication'.
> Could not read PGP secret key
Cause: premature end of stream in PartialInputStream
Now, I added a println to see what key Gradle reads from signingKey, and turns out that no matter what I put there, it always retrieves the same key, even if I put in an invalid key (this is an altered key):
lQWGBGByDfwBDADB5pWxgBT04U0bDIv/Pv0zDEYqKXt2Dubj3RcvCDAveel3eYFt
(The password is being updated though)
Why is this happening?
This is my build.gradle.kts:
import net.minecraftforge.gradle.common.util.ModConfig
import net.minecraftforge.gradle.common.util.RunConfig
import net.minecraftforge.gradle.userdev.UserDevExtension
import java.time.Instant
import java.time.format.DateTimeFormatter
// BuildScript
buildscript {
repositories {
maven(url = "https://maven.minecraftforge.net/")
jcenter()
mavenCentral()
}
dependencies {
classpath(group = "net.minecraftforge.gradle", name = "ForgeGradle", version = "4.1.+")
}
}
plugins {
idea
id("io.github.gradle-nexus.publish-plugin") version "1.0.0"
`java-library`
`maven-publish`
signing
kotlin("jvm") version "1.5.0"
}
apply(plugin = "net.minecraftforge.gradle")
// Config -> Minecraft
val forgeVersion: String by extra
val minecraftVersion: String by extra
val kffVersion: String by extra
val modVersion: String by extra
// JVM Info
println(
"""
Java: ${System.getProperty("java.version")}
JVM: ${System.getProperty("java.vm.version")} (${System.getProperty("java.vendor")})
Arch: ${System.getProperty("os.arch")}
""".trimIndent()
)
// Minecraft
configure<UserDevExtension> {
mappings("official", minecraftVersion)
#Suppress("SpellCheckingInspection")
accessTransformer(file("src/main/resources/META-INF/accesstransformer.cfg"))
runs(closureOf<NamedDomainObjectContainer<RunConfig>> {
create("client") {
workingDirectory(file("run"))
taskName = "client"
// Recommended logging data for a userdev environment
property("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP")
// Recommended logging level for the console
property("forge.logging.console.level", "debug")
mods(closureOf<NamedDomainObjectContainer<ModConfig>> {
create("loottables") {
source(sourceSets["main"])
}
})
}
create("server") {
workingDirectory(file("run"))
taskName = "server"
// Recommended logging data for a userdev environment
property("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP")
// Recommended logging level for the console
property("forge.logging.console.level", "debug")
mods(closureOf<NamedDomainObjectContainer<ModConfig>> {
create("loottables") {
source(sourceSets["main"])
}
})
}
create("data") {
workingDirectory(file("run"))
taskName = "datagen"
// Recommended logging data for a userdev environment
property("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP")
// Recommended logging level for the console
property("forge.logging.console.level", "debug")
// Specify the mod id for data generation, where to output the resulting resource, and where to look for existing resources.
args(
"--mod",
"loottables",
"--all",
"--output",
file("src/generated/resources/"),
"--existing",
file("src/main/resources/")
)
mods(closureOf<NamedDomainObjectContainer<ModConfig>> {
create("loottables") {
source(sourceSets["main"])
}
})
}
})
}
// Minecraft Dependency
// Note: Due to the way kotlin gradle works we need to define the minecraft dependency after we configure Minecraft
dependencies {
"minecraft"(group = "net.minecraftforge", name = "forge", version = "$minecraftVersion-$forgeVersion")
implementation(group = "thedarkcolour", name = "kotlinforforge", version = "latest.release")
testImplementation(
group = "org.jetbrains.kotlin",
name = "kotlin-test-junit5",
version = kotlin.coreLibrariesVersion
)
}
repositories {
maven {
name = "kotlinforforge"
url = uri("https://thedarkcolour.github.io/KotlinForForge/")
}
}
// Setup
project.group = "com.theonlytails"
project.version = modVersion
base.archivesBaseName = "loottables"
// Sets the toolchain to compile against OpenJDK 8
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
vendor.set(JvmVendorSpec.ADOPTOPENJDK)
}
}
// Finalize the jar by re-obfuscating
tasks.named<Jar>("jar") {
// Manifest
manifest {
attributes(
"Specification-Title" to "LootTables",
"Specification-Vendor" to "TheOnlyTails",
"Specification-Version" to "1",
"Implementation-Title" to "LootTables",
"Implementation-Version" to project.version,
"Implementation-Vendor" to "TheOnlyTails",
"Implementation-Timestamp" to DateTimeFormatter.ISO_INSTANT.format(Instant.now()),
"FMLModType" to "LIBRARY"
)
}
#Suppress("SpellCheckingInspection")
finalizedBy("reobfJar")
}
// Publishing to maven central
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "com.theonlytails"
artifactId = "loottables"
version = modVersion
from(components["java"])
pom {
name.set("LootTables")
description.set("A Kotlin DSL for creating loot tables in Minecraft Forge mods")
url.set("https://github.com/theonlytails/loottables")
properties.set(mapOf("project.build.sourceEncoding" to "UTF-8"))
licenses {
license {
name.set("MIT License")
url.set("https://www.opensource.org/licenses/mit-license.php")
distribution.set("repo")
}
}
developers {
developer {
id.set("theonlytails")
name.set("TheOnlyTails")
url.set("https://theonlytails.com/")
}
}
issueManagement {
url.set("https://github.com/theonlytails/loottables/issues")
system.set("GitHub Issues")
}
scm {
connection.set("scm:git:git:github.com/theonlytails/loottables.git")
developerConnection.set("scm:git:git#github.com:theonlytails/loottables.git")
url.set("https://github.com/theonlytails/loottables")
}
}
}
}
}
java {
withJavadocJar()
withSourcesJar()
}
signing {
val signingPassword: String? by extra
val signingKey: String? by extra
println(signingKey) // this is for debbuging purposes only, I'm obviously going to remove this once done
println(signingPassword)
useInMemoryPgpKeys(
signingKey ?: throw GradleException("Couldn't find a signing password"),
signingPassword ?: throw GradleException("Couldn't find a signing key")
)
sign(publishing.publications["maven"])
}
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(System.getenv("MAVEN_USERNAME"))
password.set(System.getenv("MAVEN_PASSWORD"))
}
}
}
// Testing
tasks.withType<Test> {
useJUnitPlatform()
}

Getting newly published package from JitPack fails

I'm trying to publish my java library to JitPack using the maven-publish plugin in Gradle. I have done all that the docs have said, and JitPack says publishing was a success, but it seems like I cannot install my library, even if I just copy and paste straight from JitPack's repository.
I tried pushing straight to master on the github repo. I also changed the artifact id to sertain-core and the version to 1.0.0, as that is what is specified in the publish block. I even checked the repository url and downloaded the jar manually, and it worked fine. It seems that the only problem is downloading the jar using it's maven coordinates.
Here's my library's build file (the dependencies block is in another file and works fine):
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val ktlint by configurations.creating
plugins {
kotlin("jvm") version "1.3.50"
`maven-publish`
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect", "1.3.50"))
implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-core", "1.3.1")
implementation("org.jetbrains.kotlin", "kotlin-reflect", "1.3.50")
implementation("edu.wpi.first.wpilibj", "wpilibj-java", "2019.4.1")
implementation("edu.wpi.first.hal", "hal-java", "2019.4.1")
implementation("edu.wpi.first.ntcore", "ntcore-java", "2019.4.1")
implementation("com.ctre.phoenix", "api-java", "5.14.1")
ktlint("com.pinterest:ktlint:0.34.2")
}
tasks {
val ktlint by creating(JavaExec::class) {
group = "verification"
description = "Check Kotlin code style."
classpath = configurations["ktlint"]
main = "com.pinterest.ktlint.Main"
args = listOf("src/**/*.kt")
}
"check" {
dependsOn(ktlint)
}
create("ktlintFormat", JavaExec::class) {
group = "formatting"
description = "Fix Kotlin code style deviations."
classpath = configurations["ktlint"]
main = "com.pinterest.ktlint.Main"
args = listOf("-F", "src/**/*.kt")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += setOf("-Xuse-experimental=kotlin.Experimental")
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "org.sert2521.sertain"
artifactId = "sertain-core"
version = "1.0.0"
from(components["java"])
artifact("$buildDir/libs/${project.name}.jar")
}
}
}
And here's the build file of the project that should install the library
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.50"
id "edu.wpi.first.GradleRIO" version "2019.4.1"
}
ext.kotlinVersion = "1.3.50"
tasks.whenTaskAdded { task ->
if (task.name == "deploy" || task.name == "deployMain" || task.name == "simulateJava") task.dependsOn "assemble"
}
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url "http://first.wpi.edu/FRC/roborio/maven/release" }
maven { url "http://devsite.ctr-electronics.com/maven/release" }
maven { url "https://www.kauailabs.com/maven2" }
maven { url "http://www.revrobotics.com/content/sw/max/sdk/maven/" }
maven { url 'https://jitpack.io' }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1"
compile "com.kauailabs.navx.frc:navx-java:3.1.344"
compile "org.jetbrains.kotlin:kotlin-reflect:1.3.50"
compile wpi.deps.wpilib()
compile wpi.deps.vendor.java()
nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)
nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)
implementation 'com.github.SouthEugeneRoboticsTeam:sertain:publishing-f3bdecc967-1'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
deploy {
targets {
roboRIO("roborio") {
team = frc.getTeamOrDefault(2521)
}
}
artifacts {
frcJavaArtifact("frcJava") {
targets << "roborio"
debug = frc.getDebugOrDefault(false)
}
fileTreeArtifact("frcStaticFileDeploy") {
files = fileTree(dir: "src/main/deploy")
targets << "roborio"
directory = "/home/lvuser/deploy"
}
}
}
jar {
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
manifest {
attributes(
"Main-Class": "org.sert2521.example.MainKt"
)
}
}
wrapper {
gradleVersion = "5.0"
}
There are no error messages when publishing the library. When installing the library, there is only the usual error from gradle not being able to find a dependency.

Kotlin Multiplatform Library Project Upload Issue - POM Multiple Artifacts

We have a Kotlin multi-platform library project with a build script which builds for various platforms, i.e. common, JS & JVM, using the "old-style" sub-project structure and processes. Under this system, the artifacts produced can be successfully uploaded to our Sonatype Nexus repo (the root build.gradle is included below (1)).
We are now trying to convert to the "new-style" Kotlin multi-platform approach/structure (Building Multiplatform Projects with Gradle), but we are getting the following error when we try to upload the artifacts to the repo (the modified root build.gradle included below (2)):
BUILD FAILED in 0s
8 actionable tasks: 1 executed, 7 up-to-date
A POM cannot have multiple artifacts with the same type and classifier. Already have MavenArtifact objjson-metadata:jar.asc:asc:null, trying to add MavenArtifact objjson-metadata:jar.asc:asc:null.
10:36:52: Task execution finished 'uploadArchives'.
Does anyone know why we get this error?
The settings for each artifact created during the build seem to need to be updated in the script, but we are not sure how to do that.
Thanks in advance!
(1) Original ("old-style" multi-platform) root build.gradle:
buildscript {
ext.kotlinVersion = '1.2.61'
repositories {
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
}
}
plugins {
id 'io.codearte.nexus-staging' version '0.11.0'
}
allprojects {
group 'nz.salect.objJSON'
version '0.24-SNAPSHOT'
}
ext {
libraries = [
kotlin_stdlib : "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion",
kotlin_stdlib_common : "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion",
kotlin_stdlib_js : "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion",
kotlin_reflect_lib : "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion",
kotlin_test : "org.jetbrains.kotlin:kotlin-test:$kotlinVersion",
kotlin_test_common : "org.jetbrains.kotlin:kotlin-test-common:$kotlinVersion",
kotlin_test_js : "org.jetbrains.kotlin:kotlin-test-js:$kotlinVersion",
kotlin_test_annotations_common: "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlinVersion",
kotlin_test_junit : "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion",
]
}
subprojects {
repositories {
jcenter()
mavenCentral()
}
//Nexus/Maven upload settings
apply plugin: 'com.bmuschko.nexus'
modifyPom {
project {
name 'objJSON'
description 'A JSON serialization library fully implemented in Kotlin.'
url 'https://bitbucket.org/objdict/objjson'
inceptionYear '2016'
scm {
url 'https://bitbucket.org/objdict/objjson'
connection 'scm:https://bitbucket.org/objdict/objjson.git'
developerConnection 'scm:git://bitbucket.org/objdict/objjson.git'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'xxx'
name 'xxx'
email 'xxx'
}
}
}
}
extraArchive {
sources = true
tests = true
javadoc = true
}
nexus {
sign = true
repositoryUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
snapshotRepositoryUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
}
//End Nexus/Maven upload settings
}
nexusStaging {
packageGroup = "nz.salect"
}
(2) Updated ("new-style" multi-platform) root build.gradle:
buildscript {
ext.kotlinVersion = "1.3.11"
repositories {
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("com.bmuschko:gradle-nexus-plugin:2.3.1")
}
}
plugins {
// from the multiplatform reference file
id "kotlin-multiplatform" version "1.3.11"
id "maven-publish"
id "io.codearte.nexus-staging" version "0.11.0"
//Nexus/Maven upload settings
//id "bmuschko.nexus"
}
//Nexus/Maven upload settings
apply plugin: "com.bmuschko.nexus"
//ext { - all moved to buildSrc
// libraries = [
// kotlin_stdlib: "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion",
// kotlin_stdlib_common: "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion",
// kotlin_stdlib_js: "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion",
//
// kotlin_reflect_lib: "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion",
//
// kotlin_test: "org.jetbrains.kotlin:kotlin-test:$kotlinVersion",
// kotlin_test_common: "org.jetbrains.kotlin:kotlin-test-common:$kotlinVersion",
// kotlin_test_js: "org.jetbrains.kotlin:kotlin-test-js:$kotlinVersion",
// kotlin_test_annotations_common: "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlinVersion",
//
// kotlin_test_junit: "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion",
// ]
//}
allprojects {
group "nz.salect.objJSON"
version Share.version
repositories {
jcenter()
mavenCentral()
}
modifyPom {
project {
name "objJSON"
description "A JSON serialization library fully implemented in Kotlin."
url "https://bitbucket.org/objdict/objjson"
inceptionYear "2016"
scm {
url "https://bitbucket.org/objdict/objjson"
connection "scm:https://bitbucket.org/objdict/objjson.git"
developerConnection "scm:git://bitbucket.org/objdict/objjson.git"
}
licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
developers {
developer {
id "xxx"
name "xxx"
email "xxx"
}
}
}
}
extraArchive {
sources = true
tests = true
javadoc = true
}
nexus {
sign = true
repositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
snapshotRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
}
//End Nexus/Maven upload settings
}
nexusStaging {
packageGroup = "nz.salect"
}
repositories {
mavenCentral()
}
kotlin {
targets {
fromPreset(presets.jvm, "jvm") {
mavenPublication {
artifactId = "objjson-jvm"
}
}
fromPreset(presets.js, "js") {
mavenPublication {
artifactId = "objjson-js"
}
}
// For ARM, preset should be changed to presets.iosArm32 or presets.iosArm64
// For Linux, preset should be changed to e.g. presets.linuxX64
// For MacOS, preset should be changed to e.g. presets.macosX64
//fromPreset(presets.mingwX64, "mingw")
}
sourceSets {
commonMain {
dependencies {
implementation("$Libraries.kotlin_stdlib_common")
implementation("$Libraries.kotlin_reflect_lib")
}
}
commonTest {
dependencies {
implementation("$Libraries.kotlin_test_common")
implementation("$Libraries.kotlin_test_annotations_common")
}
}
jvmMain {
dependencies {
implementation("$Libraries.kotlin_stdlib")
implementation("$Libraries.kotlin_reflect_lib")
}
}
jvmTest {
dependencies {
implementation("$Libraries.kotlin_test")
implementation("$Libraries.kotlin_test_junit")
}
}
jsMain {
dependencies {
implementation("$Libraries.kotlin_stdlib_js")
}
}
jsTest {
dependencies {
implementation("$Libraries.kotlin_test_js")
}
}
mingwMain {
}
mingwTest {
}
}
}

How to publish(deploy) multiple zip files to artifactory using gradle?

I would like to upload multiple zip files(from different directories) to artifactory using gradle script. I was able to upload single distribution using below code.
distributions {
main {
baseName = 'sample'
contents {
from{'src/main/dist/sample'}
}
}
}
publishing {
repositories {
maven {
url "${artifactoryURL}/myFiles"
credentials {
username artifactoryUser
password artifactoryPassword
}
}
}
publications {
distribution(MavenPublication) {
groupId 'com.test'
artifactId 'sample'
version version
artifact (distZip) {
}
}
}
}
Please help in uploading multiple zip files from different source ("src/main/dist/second").
This is full example of build.gragle. To publish zips you should run distZip artifactoryPublish
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
}
}
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'distribution'
//Defining list of our distributions, every value is map which contains value and version of every distribution
def dists = [
[name:'sample', version: 1],
[name:'second', version: 1]
]
distributions {
//Creating distribution from each value of the distributions list defined above
dists.each { dist ->
"$dist.name" {
baseName = "$dist.name"
contents {
from{"src/main/dist/${dist.name}"}
}
}
}
}
//Every new distribution creates task "${distributionName}DistZip" so we make posible to run them with base task distZip
distZip.dependsOn {
tasks.findAll{ task -> task.name.endsWith('DistZip') }
}
publishing {
publications {
//Again iterating list to make publication for every distribution
dists.each { dist ->
//Every publication has name of the distibution
"$dist.name"(MavenPublication) {
groupId "test"
version = dist.version
artifactId = dist.name
artifact("$buildDir/distributions/${dist.name}.zip")
}
}
}
}
artifactory {
contextUrl = "$URL"
publish {
repository {
repoKey = 'REPO_KEY'
username = USER_NAME
password = PASSWORD
}
defaults {
//Publish every distribution to Artifactory
dists.each { dist ->
publications(dist.name)
}
}
}
}

Resources