Skip to content

Commit

Permalink
Update versions of things and cleanup "stuff".
Browse files Browse the repository at this point in the history
This publishes the correct versions of things when executed, as expected. Plus removed non-useful stuff.
  • Loading branch information
EAGrahamJr committed Jan 11, 2025
1 parent 8a3269a commit 04f243a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 106 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Ch-ch-changes

### 1.2.0

- Fix plugin references to be sane
- Remove `protobuf` publishing as it could get messy with other `sourceSets`
- More transitive dependencies with the `generateProtobuf` plugin

### 1.1.0

- Proper plugin referencing
Expand Down
48 changes: 20 additions & 28 deletions Plugin List.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<!-- TOC -->
* [Gradle Script Plugins](#gradle-script-plugins)
* [About Maven Credentials](#about-maven-credentials)
* [List of Plugins](#list-of-plugins)
* [library-publish](#library-publish)
* [Usage](#usage)
* [generate-protobuf](#generate-protobuf)
* [Usage](#usage)
* [docker-build](#docker-build)
* [Usage](#usage)
* [Example Build Script](#example-build-script)
* [Example Docker File](#example-docker-file)
* [List of Tasks](#list-of-tasks)
* [Publish Java Library](#publish-java-library)
* [Usage](#usage)
* [Generate Java and Kotlin `protobuf` implementations](#generate-java-and-kotlin-protobuf-implementations)
* [Usage](#usage-1)
<!-- TOC -->

# Gradle Script Plugins
Expand All @@ -33,6 +29,10 @@ Publishes source and binary JAR files for "library" projects to a Maven reposito

#### Usage

```kotlin
id("crackers.buildstuff.library-publish")
```

* **Tasks**
* `libraryDistribution`creates and publishes the binary and source JARs
* if the **environment** variable `PUBLISH_LIBRARY` is _true_, the artifacts are pushed to the designated repository
Expand All @@ -49,31 +49,23 @@ Publishes source and binary JAR files for "library" projects to a Maven reposito

### Generate Java and Kotlin `protobuf` implementations

Generates and publishes `protobuf` libraries. It is an extention of the above _ Publish Java Library_.
Generates `protobuf` libraries.

This plugin:

* sets up IDEA "source directories" so generated source is available to projects
* creates artifacts with the project version
* a ZIP file containting the `protobuf` definitions
* a Java JAR file, with the pre-compiled classes
* message classes are compiled to Java
* service classes are compiled to both Java and Kotln client/server stubs
* **stub** dependencies included transitively (_not_ the runtime-libraries)
* publishes all the artifacts to a Maven repository
* if the **environment** varible `PUBLISH_PROTO` is _true_, the artifacts are pushed to the designated repository
* otherwise they are published "locally"
* message classes are compiled to Java
* service classes are compiled to both Java and Kotln client/server stubs
* **stub** dependencies included transitively (_including_ the runtime-libraries)

#### Usage

* **Tasks**
* `protoDistribution` compiles, packages, and publishes the `protobuf`
* `buildProto` executes `clean`, then `protoDistribution`
* **Requirements**
* `protobuf` files are in `src/main/proto`
* `group`, `module`, and `version` properties are properly set
```kotlin
id("crackers.buildstuff.generate-protobuf")
```

This is simply just the "typical" `protobuf` generate setup as [documented](https://github.com/google/protobuf-gradle-plugin), nothing "fancy" added: just the Java and Kotlin generation parts. This should be completely transparent when used and all other options available should be available.

* **Properties**
* `protobuf.javaVersion` - the JVM version to target (default is _17_)
* `protobuf.publish.repoName` - the name of the "publish" repository to target
* `protobuf.publish.repoUrl` - the URL of the "publish" repository
* `protobuf.publish.insecure` - if "true" (default **false**), allows for use of an _insecure_ registry (see [above](#about-maven-credentials))
* `protobuf.javaVersion` - sets the version of Java to use; defaults to **17**
48 changes: 27 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
`kotlin-dsl`
kotlin("jvm") version "1.7.21"
kotlin("jvm") version "2.0.0"
`maven-publish`
id("net.thauvin.erik.gradle.semver") version "1.0.4"
}
Expand All @@ -26,14 +26,32 @@ gradlePlugin {
// Define the plugin
plugins {
create("libraryPublish") {
id = "crackers.buildstuff.crackers-gradle-plugins"
id = "crackers.buildstuff.library-publish"
implementationClass = "LibraryPublishPlugin"
version = project.provider {
project.file("version.properties")
.readLines()
.findLast { it.startsWith("version.semver") }!!
.split("=")[1]
}.get()
project.afterEvaluate {
version = project.version
}
}
create("protobufGen") {
id = "crackers.buildstuff.generate-protobuf"
implementationClass = "GenerateProtobufPlugin"
project.afterEvaluate {
version = project.version
}
}
}
}

fun isDefaultBranch() = System.getenv("PUBLISH_LIB") == "true"

publishing {
repositories {
// "protected" by the environment variable
if (isDefaultBranch()) {
maven {
name = "some_name"
url = uri("http://localhost")
}
}
}
}
Expand All @@ -42,19 +60,7 @@ gradlePlugin {
* Publish the plugin JAR (no sources).
*/
tasks.create("pluginPublish") {
val isDefaultBranch = System.getenv("PUBLISH_LIB") == "true"

publishing {
if (isDefaultBranch) {
repositories {
maven {
name = "some name"
url = uri("set publish URL")
}
}
}
}
if (isDefaultBranch)
if (isDefaultBranch())
dependsOn("incrementPatch", "build", "publish")
else
dependsOn("build", "publishToMavenLocal")
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
53 changes: 0 additions & 53 deletions src/main/kotlin/generate-protobuf.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ repositories {

plugins {
`java-library`
`maven-publish`
idea
id("com.google.protobuf")
}
Expand All @@ -30,9 +29,6 @@ dependencies {
implementation("javax.annotation:javax.annotation-api:1.3.2")
}

val protoFiles = "$projectDir/src/main/proto"
val outputDestination = "$projectDir/build/protoDist"

/**
* Make the generated classes "visible" to IDEA
*/
Expand Down Expand Up @@ -68,52 +64,3 @@ protobuf {
}
}
}

/**
* Sets up a ZIP file containing only the protobuf file(s) for publishing.
*/
tasks.register("packageDistributionZip", Zip::class.java) {
getDestinationDirectory().set(file(outputDestination))
from(protoFiles)
}

/**
* Publish! Destination depends on the environment variable.
*/
tasks.create("protoDistribution") {
val publishToRepo = System.getenv("PUBLISH_PROTO") == "true"

publishing {
publications {
create<MavenPublication>("library") {
from(components["java"])
artifact(tasks.findByName("packageDistributionZip"))
artifactId = project.name
}
}
if (publishToRepo) {
val repoName = project.findProperty("protobuf.publish.repoName")?.toString() ?: throw GradleException("Property 'protobuf.publish.repoName' was not set")
val repoUrl = project.findProperty("protobuf.publish.repoUrl")?.toString() ?: throw GradleException("Property 'protobuf.publish.repoUrl' was not set")

repositories {
maven {
name = repoName
url = uri(repoUrl)
credentials {
username = System.getenv("MAVEN_ACTOR") ?: throw GradleException("Environment variable 'MAVEN_ACTOR' was not set")
password = System.getenv("MAVEN_TOKEN") ?: throw GradleException("Environment variable 'MAVEN_TOKEN' was not set")
}
}
}
}
}
dependsOn("packageDistributionZip")
if (publishToRepo)
dependsOn("publish")
else
dependsOn("publishToMavenLocal")
}

task("buildProto") {
dependsOn("clean", "protoDistribution")
}
6 changes: 3 additions & 3 deletions version.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#Generated by the Semver Plugin for Gradle
#Sun Jan 05 10:14:34 PST 2025
#Sat Jan 11 13:42:28 PST 2025
version.buildmeta=
version.major=1
version.minor=1
version.minor=2
version.patch=0
version.prerelease=
version.semver=1.1.0
version.semver=1.2.0

0 comments on commit 04f243a

Please sign in to comment.