Skip to content

Commit

Permalink
Implement MavenPublishConfiguration (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
iselo authored Aug 24, 2023
1 parent ddb7ff5 commit 0fa0e9e
Show file tree
Hide file tree
Showing 17 changed files with 395 additions and 148 deletions.
86 changes: 56 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build.gradle.kts
---

~~~Kotlin
import co.raccoons.local.gradle.GradleBuild
import co.raccoons.local.gradle.BuildWorkflow
import co.raccoons.local.gradle.checkstyle.CheckstyleConfiguration
import co.raccoons.local.gradle.checkstyle.CheckstyleReportFormat
import co.raccoons.local.gradle.jacoco.JacocoConfiguration
Expand All @@ -24,49 +24,75 @@ import co.raccoons.local.gradle.java.TestImplementation
import co.raccoons.local.gradle.javacompile.Version
import co.raccoons.local.gradle.javadoc.JavadocConfiguration
import co.raccoons.local.gradle.javadoc.JavadocTag
import co.raccoons.local.gradle.publish.MavenPublishConfiguration
import co.raccoons.local.gradle.publish.maven.Pom
import co.raccoons.local.gradle.publish.maven.License
import co.raccoons.local.gradle.publish.maven.Publication
import co.raccoons.local.gradle.repository.Repository
import co.raccoons.local.gradle.test.TestNG

GradleBuild.of(project)
.use(Repository.MAVEN_CENTRAL)
BuildWorkflow.of(project)
.setGroup("co.raccoons")
.setVersion("1.0")
.use(Repository.MAVEN_LOCAL)
.use(Configuration.javaLibrary)
.use(Repository.MAVEN_CENTRAL)
.use(JavaLibraryConfiguration.default())
.use(Version.JAVA.of(20))
.use(Configuration.testNG)
.use(Configuration.jacoco)
.use(Configuration.javadoc)
.use(Configuration.checkstyle)
.use(Configuration.testNG())
.use(Configuration.jacoco())
.use(Configuration.javadoc())
.use(Configuration.checkstyle())
.use(Configuration.mavenPublish())

internal class Configuration {
companion object {
internal object Configuration {

val javaLibrary =
JavaLibraryConfiguration.default()
fun testNG() =
TestNG.newBuilder()
.addDependency(TestImplementation("org.testng", "testng", "7.8.0"))
.addDependency(TestImplementation("org.slf4j", "slf4j-simple", "2.0.7"))
.build()

val testNG =
TestNG.Builder()
.addDependency(TestImplementation("org.testng", "testng", "7.8.0"))
.addDependency(TestImplementation("org.slf4j", "slf4j-simple", "2.0.7"))
.build()
fun jacoco() =
JacocoConfiguration.newBuilder()
.enable(JacocoReportFormat.HTML)
.enable(JacocoReportFormat.XML)
.build()

val jacoco =
JacocoConfiguration.Builder()
.enable(JacocoReportFormat.HTML)
.enable(JacocoReportFormat.XML)
fun javadoc() =
JavadocConfiguration.newBuilder()
.addTag(JavadocTag("apiNote", "API Note"))
.addTag(JavadocTag("implSpec", "Implementation Specification"))
.addTag(JavadocTag("implNote", "Implementation Note"))
.build()

fun checkstyle() =
CheckstyleConfiguration.newBuilder()
.setVersion("10.12.2")
.enable(CheckstyleReportFormat.HTML)
.build()

fun mavenPublish(): MavenPublishConfiguration {
val license =
License.newBuilder()
.setName("Meeko")
.setUrl("https://opensource.org/license/mit")
.build()

val javadoc =
JavadocConfiguration.Builder()
.addTag(JavadocTag("apiNote", "API Note"))
.addTag(JavadocTag("implSpec", "Implementation Specification"))
.addTag(JavadocTag("implNote", "Implementation Note"))
val pom =
Pom.newBuilder()
.setName("Meeko")
.setDescription("Java Base Util")
.setUrl("https://bus.raccoons.co/artefacts/meeko")
.setLicense(license)
.build()

val checkstyle =
CheckstyleConfiguration.Builder()
.setVersion("10.12.2")
.enable(CheckstyleReportFormat.HTML)
val publication =
Publication.newBuilder()
.setArtifactId("meeko")
.setPom(pom)
.build()

return MavenPublishConfiguration(publication)
}
}
~~~
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
kotlin("jvm") version "1.9.0"
id("org.jlleitschuh.gradle.ktlint") version "11.5.1"
id("com.google.protobuf") version "0.9.4"
}

repositories {
Expand All @@ -11,8 +12,15 @@ repositories {
dependencies {
implementation(kotlin("stdlib"))
implementation(gradleApi())
implementation("com.google.protobuf:protobuf-java:3.24.1")
}

kotlin {
jvmToolchain(JavaLanguageVersion.of(20).asInt())
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.24.1"
}
}
59 changes: 59 additions & 0 deletions buildSrc/src/main/kotlin/co/raccoons/local/gradle/BuildWorkflow.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package co.raccoons.local.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project

/**
* Gradle build configurator.
*/
object BuildWorkflow {
/**
* Returns build configuration handler of this project.
*/
fun of(project: Project): ConfigurationHandler {
/**
* Build configuration handler that applies configuration to project.
*/
class BuildConfigurationHandler(private val project: Project) : ConfigurationHandler {
/** inheritDoc */
override fun use(plugin: Plugin<Project>): ConfigurationHandler {
plugin.apply(this.project)
return this
}

/** inheritDoc */
override fun setGroup(group: String): ConfigurationHandler {
this.project.group = group
return this
}

/** inheritDoc */
override fun setVersion(version: String): ConfigurationHandler {
this.project.version = version
return this
}
}
return BuildConfigurationHandler(project)
}

interface ConfigurationHandler {
/**
* Puts plugin into operation
*/
fun use(plugin: Plugin<Project>): ConfigurationHandler

/**
* Sets the group of this project.
*
* @param group The group of this project.
*/
fun setGroup(group: String): ConfigurationHandler

/**
* Sets the version of this project.
*
* @param version The version of this project.
*/
fun setVersion(version: String): ConfigurationHandler
}
}
33 changes: 0 additions & 33 deletions buildSrc/src/main/kotlin/co/raccoons/local/gradle/GradleBuild.kt

This file was deleted.

8 changes: 7 additions & 1 deletion buildSrc/src/main/kotlin/co/raccoons/local/gradle/Presets.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/*
* Copyright 2023, Raccoons. Developing simple way to change.
*
* @license MIT
*/

package co.raccoons.local.gradle

/**
* Plugins version
* Presets for plugins versions.
*/
enum class Presets(private val version: String) {
CHECKSTYLE("10.12.2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class CheckstyleConfiguration(

private fun setupPlugin(project: Project) {
project.plugins.apply(CHECKSTYLE_PLUGIN_ID)
val checkstyleExtension = project.extensions.getByType(CheckstyleExtension::class.java)
checkstyleExtension.toolVersion = this.toolVersion
project.extensions
.getByType(CheckstyleExtension::class.java)
.toolVersion = this.toolVersion
}

private fun enableReports(project: Project) {
Expand All @@ -34,21 +35,26 @@ class CheckstyleConfiguration(
}
}

class Builder {
companion object {

private var toolVersion = Presets.CHECKSTYLE.version()
private val enabledFormats = mutableListOf<CheckstyleReportFormat>()
fun newBuilder() = Builder()

fun setVersion(version: String): Builder {
this.toolVersion = version
return this
}
class Builder {

fun enable(reportFormat: CheckstyleReportFormat): Builder {
this.enabledFormats.add(reportFormat)
return this
}
private var toolVersion = Presets.CHECKSTYLE.version()
private val enabledFormats = mutableListOf<CheckstyleReportFormat>()

fun setVersion(version: String): Builder {
this.toolVersion = version
return this
}

fun build() = CheckstyleConfiguration(this.toolVersion, this.enabledFormats)
fun enable(reportFormat: CheckstyleReportFormat): Builder {
this.enabledFormats.add(reportFormat)
return this
}

fun build() = CheckstyleConfiguration(this.toolVersion, this.enabledFormats)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import org.gradle.testing.jacoco.tasks.JacocoReport

private const val JACOCO_PLUGIN_ID = "jacoco"

class JacocoConfiguration(private val reportFormats: List<JacocoReportFormat>) : Plugin<Project> {
class JacocoConfiguration private constructor(private val reportFormats: List<JacocoReportFormat>) :
Plugin<Project> {

override fun apply(project: Project) {
this.setupPlugin(project)
Expand All @@ -29,15 +30,22 @@ class JacocoConfiguration(private val reportFormats: List<JacocoReportFormat>) :
}
}

class Builder {
companion object {
/**
* Returns new JacocoConfigurationBuilder instance.
*/
fun newBuilder() = Builder()

private val enabledFormats = mutableListOf<JacocoReportFormat>()
class Builder {

fun enable(reportFormat: JacocoReportFormat): Builder {
this.enabledFormats.add(reportFormat)
return this
}
private val enabledFormats = mutableListOf<JacocoReportFormat>()

fun enable(reportFormat: JacocoReportFormat): Builder {
this.enabledFormats.add(reportFormat)
return this
}

fun build() = JacocoConfiguration(this.enabledFormats)
fun build() = JacocoConfiguration(this.enabledFormats)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class DependencyScope : Plugin<Project> {
}
}

fun add(dependency: Dependency) {
fun add(dependency: Dependency): DependencyScope {
this.dependencies.getOrPut(dependency.configurationName()) {
mutableListOf()
}.add(dependency.dependencyNotation().toString())

return this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2023, Raccoons. Developing simple way to change.
*
* @license MIT
*/

package co.raccoons.local.gradle.java

private const val CONFIGURATION_NAME = "implementation"

class Implementation(
group: String,
name: String,
version: String
) : Dependency(CONFIGURATION_NAME, DependencyNotation(group, name, version))
Loading

0 comments on commit 0fa0e9e

Please sign in to comment.