Skip to content

Commit 8b2f634

Browse files
authored
Remove invocations of Task.project (#9)
* remove usage of project in task, but apply plugin in subprojects * inject DependencyManagementServices to resolve dependencies * update and refactor docs to markdown * remove project reference for manual publish * change to 8.13 as min gradle version * gradle 8.13 upgrade and api change with ModuleComponentRepositoryAccess
1 parent f1d433e commit 8b2f634

File tree

20 files changed

+279
-216
lines changed

20 files changed

+279
-216
lines changed

README.adoc

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Semantic Version Gradle Plugin
2+
3+
* [docs](https://github.com/countableSet/semantic-version-plugin/tree/main/docs)
4+
* [gradle plugin portal](https://plugins.gradle.org/plugin/dev.poolside.gradle.semantic-version)
5+
6+
Based on a given `major.minor` version, plugin determines patch version based on what is already maven repository by auto incrementing it to produce the next version number. Major or minor versions must be manually changed.
7+
8+
```groovy
9+
plugins {
10+
id 'maven-publish'
11+
id 'dev.poolside.gradle.semantic-version' version '<version>'
12+
}
13+
```

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies {
1919
}
2020

2121
gradlePlugin {
22-
website.set("https://semantic-version.gradle.poolside.dev")
22+
website.set("https://github.com/countableSet/semantic-version-plugin")
2323
vcsUrl.set("https://github.com/countableSet/semantic-version-plugin")
2424

2525
plugins {
@@ -31,7 +31,7 @@ gradlePlugin {
3131
displayName = "Poolside Semantic Version Plugin"
3232
description = "Based on a given major.minor version, plugin determines patch version based on what is already " +
3333
"maven repository by auto incrementing it to produce the next version number. Major or minor versions " +
34-
"must be manually changed"
34+
"must be manually changed."
3535
tags.set(listOf("semantic version", "maven", "publish", "auto increment"))
3636
}
3737
}

docs/README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<!-- Generated with https://github.com/thlorenz/doctoc -->
2+
<!-- doctoc docs/README.md >
3+
4+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
5+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
6+
**Table of Contents**
7+
8+
- [Change Log](#change-log)
9+
- [Usage](#usage)
10+
- [Auto mode](#auto-mode)
11+
- [Manual mode](#manual-mode)
12+
- [Gradle Version Requirement](#gradle-version-requirement)
13+
14+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
15+
16+
Gradle plugin to auto-increments the patch version on each call to the `publish` task by looking up the most recent version published in the publishing maven repository and adds it by one.
17+
18+
Tested to work in the following scenarios:
19+
20+
* Single root project publication
21+
* Single and multiple subprojects publication
22+
* BOM references via `api(platform(project(":bom")))` and `java-platform` plugin
23+
* Manual versioning, prevents the task from publishing if the version isn't different from the one in maven
24+
25+
![example](semantic-version-plugin.svg)
26+
27+
## Change Log
28+
29+
See [releases](https://github.com/countableSet/semantic-version-plugin/releases) for changes.
30+
31+
## Usage
32+
33+
[Plugins Portal](https://plugins.gradle.org/plugin/dev.poolside.gradle.semantic-version)
34+
35+
```kotlin
36+
plugins {
37+
`maven-publish`
38+
id("dev.poolside.gradle.semantic-version") version "{version}"
39+
}
40+
```
41+
42+
```sh
43+
$ ./gradlw publish
44+
[...]
45+
> Task :semanticVersion
46+
Resolved published version of 'dev.poolside.test:my-library:0.1.4' to '0.1.5'
47+
[...]
48+
```
49+
50+
### Auto mode
51+
52+
Basic full example, but it can also be used for subprojects and bom subprojects. However, make sure the publication version number is in the format of `[\d]+\.[\d]+`.
53+
54+
```kotlin
55+
plugins {
56+
java
57+
`maven-publish`
58+
id("dev.poolside.gradle.semantic-version") version "{version}"
59+
}
60+
repositories {
61+
mavenCentral()
62+
}
63+
64+
group = "dev.poolside.test"
65+
version = "0.1"
66+
67+
publishing {
68+
publications {
69+
create<MavenPublication>("mavenJava") {
70+
artifactId = "my-library"
71+
from(components["java"])
72+
}
73+
}
74+
}
75+
```
76+
77+
### Manual mode
78+
79+
If there's a scenario in which you want to manually increment the semantic version. Therefore, the plugin will disable publishing if the version already exists in the repository.
80+
81+
```kotlin
82+
semanticVersion {
83+
manual = true
84+
}
85+
```
86+
87+
## Gradle Version Requirement
88+
89+
The plugin now requires Gradle version 8.13+ to access new methods and public api changes from gradle.
90+
91+
```sh
92+
❯ gr semanticVersion
93+
> Task :client:semanticVersion FAILED
94+
95+
FAILURE: Build failed with an exception.
96+
97+
* What went wrong:
98+
Execution failed for task ':client:semanticVersion'.
99+
> org/gradle/api/internal/initialization/StandaloneDomainObjectContext
100+
101+
* Try:
102+
> Run with --stacktrace option to get the stack trace.
103+
> Run with --info or --debug option to get more log output.
104+
> Run with --scan to get full insights.
105+
> Get more help at https://help.gradle.org.
106+
107+
BUILD FAILED in 1s
108+
2 actionable tasks: 2 executed
109+
```

docs/antora.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/development.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<!-- Generated with https://github.com/thlorenz/doctoc -->
2+
<!-- doctoc docs/development.md >
3+
4+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
5+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
6+
**Table of Contents**
7+
8+
- [Development](#development)
9+
- [Gradle Plugin Publishing](#gradle-plugin-publishing)
10+
- [References](#references)
11+
- [General](#general)
12+
- [pom.withXml](#pomwithxml)
13+
14+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
15+
16+
## Development
17+
18+
[Gradle docs](https://docs.gradle.org/current/userguide/writing_plugins.html) on writing plugins.
19+
20+
Publish to mavenLocal
21+
22+
```sh
23+
❯ gr publishToMavenLocal
24+
25+
BUILD SUCCESSFUL in 5s
26+
11 actionable tasks: 8 executed, 3 up-to-date
27+
```
28+
29+
Add to `settings.gradle` file in client project and change the version `id 'dev.poolside.gradle.semantic-version' version '1.0.0'`
30+
31+
```groovy
32+
pluginManagement {
33+
repositories {
34+
mavenLocal()
35+
}
36+
}
37+
```
38+
39+
## Gradle Plugin Publishing
40+
41+
* [plugin docs](https://plugins.gradle.org/docs/publish-plugin-new)
42+
* [user account](https://plugins.gradle.org/u/poolside)
43+
44+
45+
It's easier to set up credentials via the login task then doing it manually in the gradle.properties file
46+
47+
```sh
48+
❯ gr login
49+
```
50+
51+
Then run the publishing task:
52+
53+
```sh
54+
❯ gr publishPlugins
55+
56+
> Task :publishPlugins
57+
Publishing plugin dev.poolside.gradle.semantic-version version 0.1.0
58+
Thank you. Your new plugin dev.poolside.gradle.semantic-version has been submitted for approval by Gradle engineers. The request should be processed within the next few days, at which point you will be contacted via email.
59+
Publishing artifact build/publications/pluginMaven/module.json
60+
Publishing artifact build/publications/pluginMaven/pom-default.xml
61+
Publishing artifact build/libs/semantic-version-plugin-0.1.0.jar
62+
Publishing artifact build/libs/semantic-version-plugin-0.1.0-sources.jar
63+
Publishing artifact build/libs/semantic-version-plugin-0.1.0-javadoc.jar
64+
Activating plugin dev.poolside.gradle.semantic-version version 0.1.0
65+
66+
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
67+
68+
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
69+
70+
See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings
71+
72+
BUILD SUCCESSFUL in 5s
73+
10 actionable tasks: 7 executed, 3 up-to-date
74+
```
75+
76+
## References
77+
78+
Information that I found helpful when writing this plugin
79+
80+
### General
81+
82+
* https://github.com/nebula-plugins/nebula-publishing-plugin
83+
* [MavenResolvedDependenciesPlugin](https://github.com/nebula-plugins/nebula-publishing-plugin/blob/aee3fb093c622e7b7c9eb75cb6dc2838c2bcf340/src/main/groovy/nebula/plugin/publishing/maven/MavenResolvedDependenciesPlugin.groovy)
84+
* [editing pom info](https://stackoverflow.com/questions/20959558/in-gradle-how-can-i-generate-a-pom-file-with-dynamic-dependencies-resolved-to-t)
85+
86+
### pom.withXml
87+
88+
Editing groovy dom nodes/nodelists/etc is a pain in kotlin. I found these links helpful.
89+
90+
* [kotlinx.dom](https://github.com/Kotlin/kotlinx.dom/blob/0fe219d942047468b361dc0594f1c443ebcf26c3/src/main/kotlin/Dom.kt)
91+
* [kotlin-dsl-sample issue](https://github.com/gradle/kotlin-dsl-samples/issues/225)
92+
* [groovy example](https://github.com/nebula-plugins/nebula-publishing-plugin/blob/575b55c72151e0fae35c4aea69ff77ae8db57455/src/main/groovy/nebula/plugin/publishing/maven/MavenRemoveInvalidDependenciesPlugin.groovy)

docs/modules/ROOT/nav.adoc

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/modules/ROOT/pages/index.adoc

Lines changed: 0 additions & 87 deletions
This file was deleted.

docs/modules/research/nav.adoc

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/modules/research/pages/gradle-plugin.adoc

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)