diff --git a/nmcp-tasks/src/main/kotlin/nmcp/internal/task/metadata.kt b/nmcp-tasks/src/main/kotlin/nmcp/internal/task/metadata.kt index a78a5dc..1f40a12 100644 --- a/nmcp-tasks/src/main/kotlin/nmcp/internal/task/metadata.kt +++ b/nmcp-tasks/src/main/kotlin/nmcp/internal/task/metadata.kt @@ -2,10 +2,10 @@ package nmcp.internal.task import kotlinx.serialization.Serializable import kotlinx.serialization.StringFormat -import nl.adaptivity.xmlutil.serialization.XML +import nl.adaptivity.xmlutil.XmlDeclMode +import nl.adaptivity.xmlutil.core.XmlVersion import nl.adaptivity.xmlutil.serialization.XML1_0 import nl.adaptivity.xmlutil.serialization.XmlChildrenName -import nl.adaptivity.xmlutil.serialization.XmlConfig import nl.adaptivity.xmlutil.serialization.XmlElement import nl.adaptivity.xmlutil.serialization.XmlSerialName @@ -84,4 +84,9 @@ internal data class ArtifactMetadata( internal val xml: StringFormat = XML1_0.recommended { indentString = " " + // Maven Central doesn't understand XML 1.1 + // See also https://github.com/pdvrieze/xmlutil/issues/324 + xmlVersion = XmlVersion.XML10 + // Also set the charset explicitly + xmlDeclMode = XmlDeclMode.Charset } diff --git a/nmcp-tasks/src/main/kotlin/nmcp/transport/transport.kt b/nmcp-tasks/src/main/kotlin/nmcp/transport/transport.kt index 1ee986f..f82850d 100644 --- a/nmcp-tasks/src/main/kotlin/nmcp/transport/transport.kt +++ b/nmcp-tasks/src/main/kotlin/nmcp/transport/transport.kt @@ -101,7 +101,7 @@ internal class HttpTransport( response.close() return null } - if(!response.isSuccessful) { + if (!response.isSuccessful) { response.close() error("Nmcp: cannot GET '$url' (statusCode=${response.code}):\n${response.body.string()}") } @@ -127,31 +127,24 @@ internal class HttpTransport( check(response.isSuccessful) { buildString { appendLine("Nmcp: cannot PUT '$url' (statusCode=${response.code}).") - appendLine("Response body: ${response.body.string()}") + appendLine("Response body: '${response.body.string()}'") when (response.code) { + 400 -> { + appendLine("Things to double check:") + appendLine("Your artifacts have proper extensions (.jar, .pom, ...).") + appendLine("If publishing a XML file, the XML version is 1.0.") + appendLine("If publishing a snapshot, the artifacts version is ending with `-SNAPSHOT`.") + } + 401 -> { + appendLine("Check your credentials") + appendLine("If publishing a snapshot, make sure you enabled snapshots on your namespace at https://central.sonatype.com/publishing/namespaces.") + } + 403 -> { + appendLine("Check that you are publishing to the correct groupId.") + } 429 -> { appendLine("Too many requests, try again later") } - else -> { - appendLine("Things to double check:") - /** - * I have seen 401 for this - */ - appendLine(" - Are your credentials correct?") - appendLine(" - Did you enable the snapshots on your namespace at https://central.sonatype.com/publishing/namespaces?") - /** - * I have seen 400 for this - */ - appendLine(" - Is your version ending with `-SNAPSHOT`?") - /** - * I have seen 400 for this. - */ - appendLine(" - Do your artifacts have proper extensions (.jar, .pom, ...)?") - /** - * I have seen 403 for this. - */ - appendLine(" - Is your groupId correct?") - } } } } diff --git a/nmcp-tasks/src/test/kotlin/MetadataTest.kt b/nmcp-tasks/src/test/kotlin/MetadataTest.kt index 314e644..393e532 100644 --- a/nmcp-tasks/src/test/kotlin/MetadataTest.kt +++ b/nmcp-tasks/src/test/kotlin/MetadataTest.kt @@ -45,7 +45,7 @@ class MetadataTest { */ // language=xml val xmlData = """ - + com.apollographql.apollo apollo-api-jvm @@ -111,7 +111,7 @@ class MetadataTest { fun versionMetadataIsEncodedSuccessfully() { // language=xml val xmlData = """ - + com.apollographql.apollo apollo-api-jvm @@ -178,7 +178,7 @@ class MetadataTest { val result = encodeToXml(metadata) - assertEquals(xmlData, result,) + assertEquals(xmlData, result) } @Test