Skip to content

Commit

Permalink
Merge pull request #15 from dwursteisen/main
Browse files Browse the repository at this point in the history
Add version in generated Jar
  • Loading branch information
dwursteisen authored Oct 3, 2022
2 parents a144134 + 27c8513 commit a7a9f31
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.jvm.tasks.Jar
import org.gradle.plugins.signing.SigningExtension
import org.gradle.util.GradleVersion
import org.jetbrains.dokka.gradle.DokkaTask
import java.io.File
import java.net.URI

Expand Down Expand Up @@ -72,7 +73,8 @@ class MiniGdxDeveloperPlugin : Plugin<Project> {
project.extensions.configure(PublishingExtension::class.java) {
// Configure publication (what to publish)
it.publications.withType(MavenPublication::class.java).configureEach {
if(it.name != "pluginMaven") {
if (it.name != "pluginMaven") {
// TODO: [CACHE] Create variable. Push it outside lambda
it.artifact(project.tasks.getByName("javadocJar"))
}

Expand Down Expand Up @@ -112,6 +114,7 @@ class MiniGdxDeveloperPlugin : Plugin<Project> {
publication.onlyIf {
// publish on sonatype only if the username is configured.
(publication.name.startsWith("sonatype") &&
// TODO: [CACHE] Might need to do something about that.
project.properties["sonatype.username"]?.toString()?.isNotBlank() == true) ||
!publication.name.startsWith("sonatype")
}
Expand All @@ -120,12 +123,21 @@ class MiniGdxDeveloperPlugin : Plugin<Project> {
}

private fun configureDokka(project: Project) {
// TODO - [CACHE] Dokka doesn't support Configuration Cache yet
// See: https://github.com/Kotlin/dokka/issues/2231
project.apply { it.plugin("org.jetbrains.dokka") }
project.tasks.register("javadocJar", Jar::class.java) {
it.dependsOn(project.tasks.getByName("dokkaHtml"))
it.archiveClassifier.set("javadoc")
it.from(project.buildDir.resolve("dokka"))
}

project.tasks.withType(DokkaTask::class.java).whenTaskAdded { dokka ->
dokka.notCompatibleWithConfigurationCache(
"The dokka tasks are not compatible yet " +
"with the configuration cache."
)
}
}

private fun configureProjectRepository(project: Project) {
Expand All @@ -145,6 +157,7 @@ class MiniGdxDeveloperPlugin : Plugin<Project> {
project.apply { it.plugin("org.jlleitschuh.gradle.ktlint") }
}

// TODO: [CACHE] Don't pass project any more to the method
private fun copy(project: Project, filename: String, target: File) {
val content = classLoader.getResourceAsStream(filename) ?: throw MiniGdxException.create(
severity = Severity.GRAVE,
Expand All @@ -169,6 +182,7 @@ class MiniGdxDeveloperPlugin : Plugin<Project> {
it.group = "minigdx-dev"
it.description = "Copy default Github workflows inside this project."
it.doLast {
// TODO: [CACHE] Move target outside lambda
val target = it.project.projectDir.resolve(".github/workflows")
if (!target.exists()) {
it.project.mkdir(".github/workflows")
Expand All @@ -189,6 +203,7 @@ class MiniGdxDeveloperPlugin : Plugin<Project> {
it.group = "minigdx-dev"
it.description = "Copy default Makefile inside this project."
it.doLast {
// TODO: [CACHE] move target out of lambda
val target = it.project.projectDir
copy(project, "Makefile", target)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.jvm.tasks.Jar
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
Expand Down Expand Up @@ -36,6 +37,20 @@ class MiniGdxKotlinJvmPlugin : Plugin<Project> {
it.javaCompiler.set(javaCompiler)
}
}

project.tasks.withType(Jar::class.java).whenTaskAdded {
val projectName = project.name
val projectVersion = project.version.toString()

project.tasks.withType(Jar::class.java) {
it.manifest {
it.attributes(mapOf(
"Implementation-Title" to projectName,
"Implementation-Version" to projectVersion
))
}
}
}
}

private fun configurePublication(project: Project) {
Expand Down

0 comments on commit a7a9f31

Please sign in to comment.