Skip to content

Commit

Permalink
add initial gradle files.
Browse files Browse the repository at this point in the history
  • Loading branch information
portlek committed Aug 22, 2024
1 parent 1f34f42 commit 777892a
Show file tree
Hide file tree
Showing 20 changed files with 652 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto working-tree-encoding=UTF-8 eol=lf
37 changes: 37 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name-template: "$RESOLVED_VERSION"
tag-template: "$RESOLVED_VERSION"
prerelease: true
template: |
# What's Changed
$CHANGES
categories:
- title: "Breaking"
label: "breaking"
- title: "New"
label: "enhancement"
- title: "Bug Fixes"
label: "bug"
- title: "Maintenance"
label: "maintenance"
- title: "Documentation"
label: "documentation"
- title: "Dependency Updates"
label: "dependencies"
version-resolver:
major:
labels:
- "breaking"
minor:
labels:
- "enhancement"
patch:
labels:
- "bug"
- "maintenance"
- "documentation"
- "dependencies"
- "security"
exclude-labels:
- "skip-changelog"
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: "Build"
"on":
pull_request:
branches:
- "master"
jobs:
build:
name: "Build"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
- uses: "actions/setup-java@v4"
with:
distribution: "adopt"
java-version: "11"
- uses: "actions/cache@v4"
with:
path: "~/.gradle/caches"
key: "${{ runner.os }}-gradle-cache-${{ hashFiles('**/*.gradle.kts') }}"
restore-keys: |
${{ runner.os }}-gradle-
- uses: "actions/cache@v4"
with:
path: "~/.gradle/wrapper"
key: "${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle-wrapper.properties') }}"
restore-keys: |
${{ runner.os }}-gradlew-
- run: |
chmod +x gradlew
./gradlew build
16 changes: 16 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: "Update Changelog"
"on":
push:
branches:
- "master"
jobs:
changelog:
name: "Update Changelog"
runs-on: "ubuntu-latest"
if: "${{ !contains(github.event.head_commit.message, 'skip-snapshot') }}"
steps:
- uses: "release-drafter/release-drafter@master"
id: "release"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: "Release"
"on":
release:
types:
- "released"
jobs:
build:
name: "Release"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
- uses: "actions/setup-java@v4"
with:
distribution: "adopt"
java-version: "11"
- uses: "actions/cache@v4"
with:
path: "~/.gradle/caches"
key: "${{ runner.os }}-gradle-cache-${{ hashFiles('**/*.gradle.kts') }}"
restore-keys: |
${{ runner.os }}-gradle-
- uses: "actions/cache@v4"
with:
path: "~/.gradle/wrapper"
key: "${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle-wrapper.properties') }}"
restore-keys: |
${{ runner.os }}-gradlew-
- run: |
[[ "${{ github.event.release.tag_name }}" =~ ^[0-9]+(\.[0-9]+)*$ ]] || exit -1
chmod +x gradlew
./gradlew
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.gradle/
build/
.idea/
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import net.infumia.gradle.spotless

plugins { kotlin("jvm") }

repositories { mavenCentral() }

spotless()
14 changes: 14 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins { `kotlin-dsl` }

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation(libs.kotlin.plugin)
implementation(libs.dokka.plugin)
implementation(libs.spotless.plugin)
}

kotlin { jvmToolchain(11) }
5 changes: 5 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plugins { id("org.gradle.toolchains.foojay-resolver-convention") }

dependencyResolutionManagement {
versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) } }
}
43 changes: 43 additions & 0 deletions buildSrc/src/main/kotlin/net/infumia/gradle/common.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.infumia.gradle

import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.bundling.Jar
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.*
import org.jetbrains.dokka.gradle.DokkaPlugin

fun Project.applyCommon(javaVersion: Int = 8, sources: Boolean = true, javadoc: Boolean = true) {
apply<JavaPlugin>()

if (name.contains("kotlin")) {
apply<DokkaPlugin>()
apply(plugin = "org.jetbrains.kotlin.jvm")
}

repositories.mavenCentral()

extensions.configure<JavaPluginExtension> {
toolchain { languageVersion = JavaLanguageVersion.of(javaVersion) }
}

if (javadoc) {
val javadocJar by
tasks.creating(Jar::class) {
dependsOn("javadoc")
archiveClassifier.set("javadoc")
from(javadoc)
}
}

if (sources) {
val sourceSets = extensions.getByType<JavaPluginExtension>().sourceSets
val sourcesJar by
tasks.creating(Jar::class) {
dependsOn("classes")
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
}
}
16 changes: 16 additions & 0 deletions buildSrc/src/main/kotlin/net/infumia/gradle/publish.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.infumia.gradle

import org.gradle.api.Project

// TODO: portlek, Implement the publishing to gradle portal.
fun Project.publish(
// moduleName: String? = null,
javaVersion: Int = 8,
sources: Boolean = true,
javadoc: Boolean = true
) {
applyCommon(javaVersion, sources, javadoc)

// val projectName = "templator${if (moduleName == null) "" else "-$moduleName"}"
// val signRequired = project.hasProperty("sign-required")
}
71 changes: 71 additions & 0 deletions buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package net.infumia.gradle

import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessPlugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*

fun Project.spotless() {
val subProjects = subprojects.map { it.projectDir.toRelativeString(projectDir) }

repositories.mavenCentral()

apply<SpotlessPlugin>()

extensions.configure<SpotlessExtension> {
isEnforceCheck = false
lineEndings = com.diffplug.spotless.LineEnding.UNIX

val prettierConfig =
mapOf(
"prettier" to "3.3.3",
"prettier-plugin-java" to "2.6.4",
"prettier-plugin-toml" to "2.0.1",
)

yaml {
target(".github/**/*.yml")
endWithNewline()
trimTrailingWhitespace()
jackson().yamlFeature("LITERAL_BLOCK_STYLE", true).yamlFeature("SPLIT_LINES", false)
}

json {
target("renovate.json")
endWithNewline()
trimTrailingWhitespace()
jackson()
}

format("toml") {
target("gradle/libs.versions.toml")
endWithNewline()
trimTrailingWhitespace()
prettier(prettierConfig)
.config(
mapOf(
"parser" to "toml",
"plugins" to listOf("prettier-plugin-toml"),
),
)
}

kotlin {
target(
"buildSrc/src/main/kotlin/**/*.kt",
"buildSrc/**/*.gradle.kts",
"*.gradle.kts",
*subProjects.map { "$it/*.gradle.kts" }.toTypedArray(),
*subProjects.map { "$it/src/main/kotlin/**/*.kt" }.toTypedArray(),
)
endWithNewline()
trimTrailingWhitespace()
ktfmt().kotlinlangStyle().configure {
it.setMaxWidth(100)
it.setBlockIndent(4)
it.setContinuationIndent(4)
it.setRemoveUnusedImport(true)
}
}
}
}
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
group="net.infumia"
version="1.0.0-SNAPSHOT"
kotlin.code.style=official
7 changes: 7 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[versions]
kotlin = "2.0.0"

[libraries]
kotlin-plugin = { module = "org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin", version.ref = "kotlin" }
dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version = "1.9.20" }
spotless-plugin = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "6.25.0" }
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 777892a

Please sign in to comment.