Skip to content

Commit

Permalink
Merge pull request #1 from lightningkite/optional_javadoc
Browse files Browse the repository at this point in the history
Optional javadoc
  • Loading branch information
UnknownJoe796 authored Jan 18, 2022
2 parents e13e3fc + f1c129c commit 6d91b72
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
24 changes: 13 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import java.util.Properties
import java.util.*

plugins {
kotlin("jvm") version "1.6.10"
Expand All @@ -14,7 +14,7 @@ group = "com.lightningkite"
repositories {
mavenCentral()
google()
maven(url="https://plugins.gradle.org/m2/")
maven(url = "https://plugins.gradle.org/m2/")
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).all {
Expand Down Expand Up @@ -70,7 +70,7 @@ var Task.published: Boolean
this.project.artifacts.add("archives", this)
}

fun Project.sourceAndJavadoc() {
fun Project.sources(publishJavadoc: Boolean) {
tasks.apply {
this.create("sourceJar", org.gradle.jvm.tasks.Jar::class.java) {
archiveClassifier.set("sources")
Expand All @@ -84,7 +84,7 @@ fun Project.sourceAndJavadoc() {
dependsOn("dokkaJavadoc")
archiveClassifier.set("javadoc")
from(project.file("build/dokka/javadoc"))
published = true
published = publishJavadoc
}
}
}
Expand All @@ -101,7 +101,7 @@ fun File.getGitBranch(): String = runCli("git", "rev-parse", "--abbrev-ref", "HE
fun File.getGitHash(): String = runCli("git", "rev-parse", "--short", "HEAD").trim()
fun File.getGitTag(): String? = runCli("git", "tag", "--points-at", getGitHash()).trim().takeUnless { it.isBlank() }

fun Project.standardPublishing(pom: MavenPom.()->Unit) {
fun Project.standardPublishing(pom: MavenPom.() -> Unit) {
this.version = project.rootDir.run {
getGitTag() ?: (getGitBranch() + "-SNAPSHOT")
}
Expand All @@ -112,7 +112,9 @@ fun Project.standardPublishing(pom: MavenPom.()->Unit) {
val signingKey: String? = (System.getenv("SIGNING_KEY")?.takeUnless { it.isEmpty() }
?: props?.getProperty("signingKey")?.toString())
?.lineSequence()
?.filter { it.trim().firstOrNull()?.let { it.isLetterOrDigit() || it == '=' || it == '/' || it == '+' } == true }
?.filter {
it.trim().firstOrNull()?.let { it.isLetterOrDigit() || it == '=' || it == '/' || it == '+' } == true
}
?.joinToString("\n")
val signingPassword: String? = System.getenv("SIGNING_PASSWORD")?.takeUnless { it.isEmpty() }
?: props?.getProperty("signingPassword")?.toString()
Expand All @@ -133,17 +135,17 @@ fun Project.standardPublishing(pom: MavenPom.()->Unit) {
val deploymentPassword = (System.getenv("OSSRH_PASSWORD")?.takeUnless { it.isEmpty() }
?: props?.getProperty("ossrhPassword")?.toString())
?.trim()
val useDeployment = deploymentUser != null || deploymentPassword != null
val useDeployment = deploymentUser != null && deploymentPassword != null

sourceAndJavadoc()
sources(publishJavadoc = props?.getProperty("publishJavadoc")?.toBoolean() ?: true)

publishing {
publications {
create("main", MavenPublication::class.java) {
val component = components.findByName("release") ?: components.findByName("kotlin")
from(component)
for(task in tasks.asMap.values) {
if(task.published)
for (task in tasks.asMap.values) {
if (task.published)
artifact(task)
}
pom { pom(this) }
Expand All @@ -153,7 +155,7 @@ fun Project.standardPublishing(pom: MavenPom.()->Unit) {
repositories.apply {
maven {
name = "sonatype"
if(version.toString().endsWith("-SNAPSHOT")) {
if (version.toString().endsWith("-SNAPSHOT")) {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
} else {
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
Expand Down
22 changes: 10 additions & 12 deletions src/main/kotlin/helpers.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.lightningkite.deployhelpers

import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.*
import org.gradle.api.tasks.Copy
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPomDeveloperSpec
import org.gradle.api.publish.maven.MavenPomLicenseSpec
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Zip
import org.gradle.jvm.tasks.Jar
import java.util.*
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import java.io.ByteArrayOutputStream
import java.io.File
import java.util.concurrent.TimeUnit
import java.util.*

private class MarkerClass

Expand Down Expand Up @@ -52,7 +49,7 @@ var Task.published: Boolean
this.project.artifacts.add("archives", this)
}

fun Project.sourceAndJavadoc() {
fun Project.sources(publishJavadoc: Boolean) {
tasks.apply {
this.create("sourceJar", Jar::class.java) {
it.archiveClassifier.set("sources")
Expand All @@ -66,11 +63,12 @@ fun Project.sourceAndJavadoc() {
it.dependsOn("dokkaJavadoc")
it.archiveClassifier.set("javadoc")
it.from(project.file("build/dokka/javadoc"))
it.published = true
it.published = publishJavadoc
}
}
}


internal fun File.runCli(vararg args: String): String {
val process = ProcessBuilder(*args)
.directory(this)
Expand Down Expand Up @@ -118,9 +116,9 @@ fun Project.standardPublishing(pom: MavenPom.() -> Unit) {
val deploymentPassword = (System.getenv("OSSRH_PASSWORD")?.takeUnless { it.isEmpty() }
?: props?.getProperty("ossrhPassword")?.toString())
?.trim()
val useDeployment = deploymentUser != null || deploymentPassword != null
val useDeployment = deploymentUser != null && deploymentPassword != null

sourceAndJavadoc()
sources(publishJavadoc = props?.getProperty("publishJavadoc")?.toBoolean() ?: true)

publishing {
it.publications {
Expand Down

0 comments on commit 6d91b72

Please sign in to comment.