Skip to content

Commit

Permalink
add the ability to set coordinates to the base plugin (#473)
Browse files Browse the repository at this point in the history
* add the ability to set coordinates to the base plugin

* remove unnecessary assumes

* unused import
  • Loading branch information
gabrielittner committed Dec 26, 2022
1 parent 343304b commit 5aeea3f
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 162 deletions.
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Change Log

Version 0.23.0 *UNRELEASED*
---------------------------------

Updated docs can be found on [the new website](https://vanniktech.github.io/gradle-maven-publish-plugin/).

- **NEW**: It is now possible to set group id, artifact id directly through the DSL
```groovy
mavenPublishing {
coordinates("com.example", "library", "1.0.3")
}
```
- `project.group` and `project.version` will still be used as default values for group and version if the
`GROUP`/`VERSION_NAME` Gradle properties do not exist and `coordinates` was not called, however there are 2
**behavior changes**:
- The `GROUP` and `VERSION_NAME` Gradle properties take precedence over `project.group` and `project.version` instead
of being overwritten by them. If you need to define the properties but replace them for some projects,
please use the new `coordinates` method instead.
- The `GROUP` and `VERSION_NAME` Gradle properties will not be explicitly set as `project.group` and
`project.version` anymore.
- The minimum supported Gradle version has been increased to 7.3.

Version 0.22.0 *(2022-09-09)*
---------------------------------

Expand All @@ -11,7 +32,7 @@ Version 0.22.0 *(2022-09-09)*
SONATYPE_HOST=DEFAULT # or S01
SONATYPE_AUTOMATIC_RELEASE=true
```
or
or
```
mavenPublishing {
publishToMavenCentral("DEFAULT", true)
Expand Down
16 changes: 5 additions & 11 deletions docs/central.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,9 @@ This configuration also determines the coordinates (`group:artifactId:version`)
=== "build.gradle"

```groovy
group = "com.example.project"
version = "1.0.3-SNAPSHOT"
// note that it's currently not possible to modify the artifact id through the DSL
// by default `project.name` is used, to modify it use gradle.properties

mavenPublishing {
coordinates("com.example.mylibrary", "library-name", "1.0.3-SNAPSHOT")

pom {
name = "My Library"
description = "A description of what my library does."
Expand Down Expand Up @@ -126,12 +123,9 @@ This configuration also determines the coordinates (`group:artifactId:version`)
=== "build.gradle.kts"

```kotlin
group = "com.example.project"
version = "1.0.3-SNAPSHOT"
// note that it's currently not possible to modify the artifact id through the DSL
// by default `project.name` is used, to modify it use gradle.properties

mavenPublishing {
coordinates("com.example.mylibrary", "mylibrary-runtime", "1.0.3-SNAPSHOT")

pom {
name.set("My Library")
description.set("A description of what my library does.")
Expand Down Expand Up @@ -165,7 +159,7 @@ This configuration also determines the coordinates (`group:artifactId:version`)
```properties
GROUP=com.test.mylibrary
POM_ARTIFACT_ID=mylibrary-runtime
VERSION_NAME=3.0.5
VERSION_NAME=1.0.3-SNAPSHOT

POM_NAME=My Library
POM_DESCRIPTION=A description of what my library does.
Expand Down
20 changes: 6 additions & 14 deletions docs/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,11 @@ This configuration also determines the coordinates (`group:artifactId:version`)
=== "build.gradle"

```groovy
group = "com.example.project"
version = "1.0.3-SNAPSHOT"
// note that it's currently not possible to modify the artifact id through the DSL
// by default `project.name` is used, to modify it use gradle.properties

mavenPublishing {
coordinates("com.example.mylibrary", "library-name", "1.0.3-SNAPSHOT")

// the following is optional
// the following is optional

mavenPublishing {
pom {
name = "My Library"
description = "A description of what my library does."
Expand Down Expand Up @@ -115,15 +111,11 @@ This configuration also determines the coordinates (`group:artifactId:version`)
=== "build.gradle.kts"

```kotlin
group = "com.example.project"
version = "1.0.3-SNAPSHOT"
// note that it's currently not possible to modify the artifact id through the DSL
// by default `project.name` is used, to modify it use gradle.properties

mavenPublishing {
coordinates("com.example.mylibrary", "library-name", "1.0.3-SNAPSHOT")

// the following is optional
// the following is optional

mavenPublishing {
pom {
name.set("My Library")
description.set("A description of what my library does.")
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ class MavenPublishPluginIntegrationTest {
assertPomContentMatches()
}

// TODO
@Test fun generatesArtifactsAndDocumentationOnOverrideVersionGroupProject() {
setupFixture("override_version_group_project")

val result = executeGradleCommands(TEST_TASK, "--stacktrace")

assertExpectedTasksRanSuccessfully(result)
assertExpectedCommonArtifactsGenerated(groupId = "com.example2", version = "2.0.0")
assertPomContentMatches(groupId = "com.example2", version = "2.0.0")
}

/**
* Copies test fixture into temp directory under test.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.vanniktech.maven.publish

import com.google.common.truth.TruthJUnit.assume
import com.google.testing.junit.testparameterinjector.junit5.TestParameter
import com.google.testing.junit.testparameterinjector.junit5.TestParameterInjectorTest
import com.vanniktech.maven.publish.ProjectResultSubject.Companion.assertThat
Expand All @@ -24,9 +23,6 @@ class MavenPublishPluginSpecialCaseTest {

@TestParameterInjectorTest
fun artifactIdThatContainsProjectNameProducesCorrectArtifactId(@TestParameter kotlinVersion: KotlinVersion) {
// in the DSL the artifact id is not configurable
assume().that(config).isNotEqualTo(TestOptions.Config.DSL)

val project = kotlinMultiplatformProjectSpec(kotlinVersion).copy(
defaultProjectName = "foo",
artifactId = "foo-bar",
Expand Down Expand Up @@ -87,9 +83,6 @@ class MavenPublishPluginSpecialCaseTest {

@TestParameterInjectorTest
fun artifactIdThatContainsProjectNameProducesCorrectArtifactId2(@TestParameter kotlinVersion: KotlinVersion) {
// in the DSL the artifact id is not configurable
assume().that(config).isNotEqualTo(TestOptions.Config.DSL)

val project = kotlinMultiplatformProjectSpec(kotlinVersion).copy(
defaultProjectName = "foo",
artifactId = "bar-foo",
Expand Down Expand Up @@ -169,6 +162,7 @@ class MavenPublishPluginSpecialCaseTest {
fun groupAndVersionFromProjectProject() {
val project = javaProjectSpec().copy(
group = null,
artifactId = null,
version = null,
buildFileExtra = """
group = "com.example.test2"
Expand All @@ -179,6 +173,8 @@ class MavenPublishPluginSpecialCaseTest {

val resultSpec = project.copy(
group = "com.example.test2",
// the project name is used as default value for the artifact id
artifactId = "default-root-project-name",
version = "3.2.1",
)
val actualResult = result.copy(projectSpec = resultSpec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fun ProjectSpec.run(fixtures: Path, temp: Path, options: TestOptions): ProjectRe
val repo = temp.resolve("repo").apply { createDirectories() }

writeBuildFile(project.resolve("build.gradle"), repo, options)
writeSettingFile(project.resolve("settings.gradle"), options)
writeSettingFile(project.resolve("settings.gradle"))
writeGradleProperties(project.resolve("gradle.properties"), options)
writeSourceFiles(fixtures, project)
fixtures.resolve("test-secring.gpg").copyTo(project.resolve("test-secring.gpg"))
Expand Down Expand Up @@ -75,11 +75,12 @@ private fun ProjectSpec.publishingBlock(options: TestOptions): String {
return if (options.config == TestOptions.Config.DSL) {
listOfNotNull(
"""
group = "$group"
version = "$version"
mavenPublishing {
${if (options.signing != TestOptions.Signing.NO_SIGNING) "signAllPublications()" else ""}
${if (group != null && artifactId != null && version != null) "coordinates(\"$group\", \"$artifactId\", \"$version\")" else ""}
pom {
""",
" name = \"${properties["POM_NAME"]}\"".takeIf { properties.containsKey("POM_NAME") },
Expand Down Expand Up @@ -124,12 +125,7 @@ private fun ProjectSpec.publishingBlock(options: TestOptions): String {
}
}

private fun ProjectSpec.writeSettingFile(path: Path, options: TestOptions) {
val rootProjectName = if (options.config == TestOptions.Config.DSL) {
artifactId
} else {
defaultProjectName
}
private fun writeSettingFile(path: Path) {
path.writeText(
"""
pluginManagement {
Expand All @@ -148,7 +144,7 @@ private fun ProjectSpec.writeSettingFile(path: Path, options: TestOptions) {
}
}
rootProject.name = "$rootProjectName"
rootProject.name = "default-root-project-name"
""".trimIndent()
)
Expand Down

0 comments on commit 5aeea3f

Please sign in to comment.