Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Maven release issues #545

Merged
merged 6 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 41 additions & 24 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ repositories {
logger.warn("Using local Maven repository as source")
mavenLocal()
}
maven("https://jitpack.io")
mavenCentral()
maven("https://maven.scijava.org/content/groups/public")
}
Expand All @@ -45,7 +46,7 @@ dependencies {
exclude("org.lwjgl")
}

val sceneryVersion = "0.9.0"
val sceneryVersion = "de3897c"
api("graphics.scenery:scenery:$sceneryVersion") {
version { strictly(sceneryVersion) }
exclude("org.biojava.thirdparty", "forester")
Expand Down Expand Up @@ -138,6 +139,9 @@ dependencies {
// }
//}

val isRelease: Boolean
get() = System.getProperty("release") == "true"

tasks {
withType<KotlinCompile>().all {
val version = System.getProperty("java.version").substringBefore('.').toInt()
Expand Down Expand Up @@ -247,18 +251,25 @@ tasks {
"lwjgl-xxhash",
"lwjgl-remotery",
"lwjgl-spvc",
"lwjgl-shaderc")
"lwjgl-shaderc",
"lwjgl-jawt",
"log4j-1.2-api")

val toSkip = listOf("pom-scijava")

logger.quiet("Adding pom-scijava-managed dependencies for Maven publication:")

configurations.implementation.get().allDependencies.forEach {
val artifactId = it.name

if (!toSkip.contains(artifactId)) {

val propertyName = "$artifactId.version"

if (versionedArtifacts.contains(artifactId)) {
// we only add our own property if the version is not null,
// as that indicates something managed by the parent POM, where
// we did not specify an explicit version.
if (versionedArtifacts.contains(artifactId) && it.version != null) {
// add "<artifactid.version>[version]</artifactid.version>" to pom
propertiesNode.appendNode(propertyName, it.version)
}
Expand All @@ -269,7 +280,7 @@ tasks {
dependencyNode.appendNode("version", "\${$propertyName}")

// Custom per artifact tweaks
println(artifactId)
logger.quiet("* ${it.group}:$artifactId with version property \$$propertyName")
if ("\\-bom".toRegex().find(artifactId) != null) {
dependencyNode.appendNode("type", "pom")
}
Expand Down Expand Up @@ -369,11 +380,10 @@ tasks {
}
}
.forEach { className ->
println("Working on $className")
val exampleName = className.substringAfterLast(".")
val exampleType = className.substringBeforeLast(".").substringAfterLast(".")

println("Registering $exampleName of $exampleType")
logger.quiet("Registering $exampleName of $exampleType from $className")
register<JavaExec>(name = className.substringAfterLast(".")) {
classpath = sourceSets.test.get().runtimeClasspath
mainClass.set(className)
Expand Down Expand Up @@ -418,30 +428,37 @@ tasks {
}
}
}
}

val dokkaJavadocJar by tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.get().outputDirectory.get())
archiveClassifier.set("javadoc")
}
dokkaHtml {
enabled = isRelease
dokkaSourceSets.configureEach {
sourceLink {
localDirectory.set(file("src/main/kotlin"))
remoteUrl.set(URL("https://github.com/scenerygraphics/sciview/tree/main/src/main/kotlin"))
remoteLineSuffix.set("#L")
}
}
}

val dokkaHtmlJar by tasks.register<Jar>("dokkaHtmlJar") {
dependsOn(tasks.dokkaHtml)
from(tasks.dokkaHtml.get().outputDirectory.get())
archiveClassifier.set("html-doc")
}
dokkaJavadoc {
enabled = isRelease
}

jacoco {
toolVersion = "0.8.7"
}
if(project.properties["buildFatJAR"] == true) {
apply(plugin = "com.github.johnrengelman.shadow")
jar {
isZip64 = true
}
}

artifacts {
archives(dokkaJavadocJar)
archives(dokkaHtmlJar)
withType<GenerateModuleMetadata> {
enabled = false
}
}


jacoco {
toolVersion = "0.8.11"
}

java.withSourcesJar()

7 changes: 6 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ plugins {

repositories {
mavenCentral()
maven(url="https://dl.bintray.com/kotlin/dokka")
gradlePluginPortal()
// jcenter() // or maven(url="https://dl.bintray.com/kotlin/dokka")
}

dependencies {
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.8.20")
}
63 changes: 50 additions & 13 deletions buildSrc/src/main/kotlin/sciview/publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package sciview

//import gradle.kotlin.dsl.accessors._e98ba513b34f86980a981ef4cafb3d49.publishing
//import org.gradle.kotlin.dsl.`maven-publish`
import java.net.URI

// configuration of the Maven artifacts
plugins {
`maven-publish`
// id("org.jetbrains.dokka")
`java-library`
id("org.jetbrains.dokka")
}

val sciviewUrl = "https://github.com/scenerygraphics/sciview"
Expand All @@ -16,10 +16,48 @@ publishing {
create<MavenPublication>("maven") {
groupId = "sc.iview"
artifactId = rootProject.name
version = rootProject.version.toString()
val customVersion = project.properties["customVersion"]
val v = if(customVersion != null) {
if(customVersion == "git") {
val gitCommand = Runtime.getRuntime().exec("git rev-parse --verify --short HEAD")
val result = gitCommand.waitFor()

if(result == 0) {
gitCommand.inputStream.bufferedReader().use { it.readText() }.trim().substring(0, 7)
} else {
logger.error("Could not execute git to get commit hash (exit code $result). Is git installed?")
logger.error("Will fall back to default project version.")
rootProject.version
}
} else {
customVersion
}
} else {
rootProject.version
}

version = v.toString()

logger.quiet("Creating Maven publication $groupId:$artifactId:$version ...")

from(components["java"])

val dokkaJavadocJar by tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}

val dokkaHtmlJar by tasks.register<Jar>("dokkaHtmlJar") {
dependsOn(tasks.dokkaHtml)
from(tasks.dokkaHtml.flatMap { it.outputDirectory })
archiveClassifier.set("html-doc")
}


artifact(dokkaJavadocJar)
artifact(dokkaHtmlJar)

// TODO, resolved dependencies versions? https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:resolved_dependencies

pom {
Expand Down Expand Up @@ -107,15 +145,14 @@ publishing {

repositories {
maven {
// name = "sonatype" TODO
// credentials(PasswordCredentials::class)
//
// val releaseRepo = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
// val snapshotRepo = "https://oss.sonatype.org/content/repositories/snapshots/"
//
// val snapshot = rootProject.version.toString().endsWith("SNAPSHOT")
// url = URI(if (snapshot) snapshotRepo else releaseRepo)
// // url = URI("https://oss.sonatype.org/service/local/staging/deploy/maven2")
name = "scijava"
credentials(PasswordCredentials::class)

val releaseRepo = "https://maven.scijava.org/content/repositories/releases/"
val snapshotRepo = "https://maven.scijava.org/content/repositories/snapshots/"

val snapshot = rootProject.version.toString().endsWith("SNAPSHOT")
url = URI(if (snapshot) snapshotRepo else releaseRepo)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ org.gradle.jvmargs=-XX:MaxMetaspaceSize=2g
org.gradle.caching=true
jvmTarget=11
#useLocalScenery=true
kotlinVersion=1.8.22
dokkaVersion=1.8.20
kotlinVersion=1.9.21
dokkaVersion=1.9.10
scijavaParentPOMVersion=36.0.0
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rootProject.name = "sciview"

gradle.rootProject {
group = "sc.iview"
version = "0.2.0-beta-9-SNAPSHOT"
version = "0.2.0-SNAPSHOT"
description = "Scenery-backed 3D visualization package for ImageJ."
}

Expand Down
Loading