Attempt to support more use cases
This commit is contained in:
parent
bad89ac69c
commit
83e6504bb4
275
jfmod.gradle
275
jfmod.gradle
|
@ -17,6 +17,8 @@ buildscript {
|
|||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'java-library'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: com.matthewprenger.cursegradle.CurseGradlePlugin
|
||||
apply plugin: com.modrinth.minotaur.Minotaur
|
||||
apply plugin: net.fabricmc.loom.bootstrap.LoomGradlePluginBootstrap
|
||||
|
@ -24,77 +26,269 @@ apply plugin: org.ajoberstar.grgit.gradle.GrgitPlugin
|
|||
|
||||
import com.modrinth.minotaur.request.VersionType
|
||||
|
||||
static Node getOrCreateNode(Node node, String name) {
|
||||
Node dependencies = null
|
||||
for(Node n : node) {
|
||||
if(name == n.name()) {
|
||||
dependencies = n
|
||||
break
|
||||
}
|
||||
}
|
||||
if(dependencies == null) {
|
||||
dependencies = node.appendNode(name)
|
||||
}
|
||||
return dependencies
|
||||
}
|
||||
|
||||
def moduleDependencies(project, List<String> depNames) {
|
||||
def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: 'dev') }
|
||||
project.dependencies {
|
||||
deps.each {
|
||||
api it
|
||||
}
|
||||
}
|
||||
project.publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
pom.withXml {
|
||||
def depsNode = getOrCreateNode(asNode(), "dependencies")
|
||||
deps.each {
|
||||
def depNode = depsNode.appendNode("dependency")
|
||||
depNode.appendNode("groupId", it.group)
|
||||
depNode.appendNode("artifactId", it.name)
|
||||
depNode.appendNode("version", it.version)
|
||||
depNode.appendNode("scope", "compile")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch changelog
|
||||
def changelogStr = "No changelog"
|
||||
ext.currentVer = "0.0.0+nogit"
|
||||
ext.currentType = VersionType.ALPHA
|
||||
if (grgit != null) {
|
||||
ext.currentVer = "0.0.0+notag"
|
||||
grgit.open(dir: project.projectDir.toString())
|
||||
def tagList = grgit.tag.list()
|
||||
if (tagList.size() >= 1) {
|
||||
def currentTag = tagList.get(tagList.size() - 1)
|
||||
ext.currentType = VersionType.RELEASE
|
||||
version = currentTag.getName()
|
||||
switch (version[0]) {
|
||||
ext.currentVer = currentTag.getName()
|
||||
switch (ext.currentVer[0]) {
|
||||
case 'v':
|
||||
version = version.substring(1)
|
||||
ext.currentVer = ext.currentVer.substring(1)
|
||||
break
|
||||
case 'b':
|
||||
version = version.substring(1)
|
||||
ext.currentVer = ext.currentVer.substring(1)
|
||||
ext.currentType = VersionType.BETA
|
||||
break
|
||||
case 'a':
|
||||
version = version.substring(1)
|
||||
ext.currentVer = ext.currentVer.substring(1)
|
||||
ext.currentType = VersionType.ALPHA
|
||||
break
|
||||
}
|
||||
if (tagList.size() >= 2) {
|
||||
changelogStr = "Commits in " + ext.currentType.toString().toLowerCase() + " " + version + ":"
|
||||
changelogStr = "Commits in " + ext.currentType.toString().toLowerCase() + " " + ext.currentVer + ":"
|
||||
for (def commit : grgit.log{range(tagList.get(tagList.size() - 2).fullName, currentTag.fullName)}) {
|
||||
changelogStr += "\n- " + commit.shortMessage
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
version = "0.0.0+notag"
|
||||
}
|
||||
}
|
||||
else {
|
||||
version = "0.0.0+nogit"
|
||||
}
|
||||
if (!project.hasProperty("release")) {
|
||||
version += "-" + Instant.now().getEpochSecond()
|
||||
ext.currentVer += "-" + Instant.now().getEpochSecond()
|
||||
}
|
||||
println(changelogStr)
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
if (!project.hasProperty("modrinth_required_dependencies")) {
|
||||
project.modrinth_required_dependencies = ""
|
||||
}
|
||||
if (!project.hasProperty("modrinth_optional_dependencies")) {
|
||||
project.modrinth_optional_dependencies = ""
|
||||
}
|
||||
if (!project.hasProperty("curseforge_required_dependencies")) {
|
||||
project.curseforge_required_dependencies = ""
|
||||
}
|
||||
if (!project.hasProperty("curseforge_optional_dependencies")) {
|
||||
project.curseforge_optional_dependencies = ""
|
||||
}
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
group = project.maven_group
|
||||
allprojects {
|
||||
apply plugin: "java-library"
|
||||
apply plugin: "maven-publish"
|
||||
apply plugin: "fabric-loom"
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
it.options.release = 17
|
||||
}
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version
|
||||
archivesBaseName = project.archives_base_name
|
||||
group = project.maven_group
|
||||
version = "$rootProject.ext.currentVer"
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.minecraft_version}+${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
}
|
||||
|
||||
loom {
|
||||
shareRemapCaches = true
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = 'TerraformersMC'
|
||||
url = 'https://maven.terraformersmc.com/'
|
||||
}
|
||||
maven {
|
||||
name = 'LibJF'
|
||||
url = 'https://gitlab.com/api/v4/projects/25805200/packages/maven'
|
||||
}
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
configurations {
|
||||
dev
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveClassifier = "dev"
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
remapJar {
|
||||
input = file("${project.buildDir}/libs/$archivesBaseName-${project.version}-dev.jar")
|
||||
archiveFileName = "${archivesBaseName}-${project.version}.jar"
|
||||
}
|
||||
|
||||
artifacts {
|
||||
dev file: file("${project.buildDir}/libs/$archivesBaseName-${project.version}-dev.jar"), type: "jar", builtBy: jar
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
archiveClassifier = "sources"
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
tasks.withType(AbstractArchiveTask) {
|
||||
preserveFileTimestamps = false
|
||||
reproducibleFileOrder = true
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
// If Javadoc is generated, this must be specified in that task too.
|
||||
it.options.encoding = "UTF-8"
|
||||
subprojects {
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
afterEvaluate {
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
|
||||
// Minecraft 1.17 (21w19a) upwards uses Java 16.
|
||||
it.options.release = 16
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setupRepositories(repositories)
|
||||
}
|
||||
|
||||
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
|
||||
|
||||
javadoc.enabled = false
|
||||
|
||||
afterEvaluate {
|
||||
genSources.enabled = false
|
||||
unpickJar.enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
from("LICENSE") {
|
||||
rename { "${it}_${project.archivesBaseName}"}
|
||||
}
|
||||
task remapMavenJar(type: net.fabricmc.loom.task.RemapJarTask, dependsOn: jar) {
|
||||
input = jar.archiveFile
|
||||
archiveFileName = "${archivesBaseName}-${project.version}-maven.jar"
|
||||
addNestedDependencies = false
|
||||
}
|
||||
build.dependsOn remapMavenJar
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
artifact(remapMavenJar) {
|
||||
builtBy remapMavenJar
|
||||
}
|
||||
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
|
||||
pom.withXml {
|
||||
def depsNode = getOrCreateNode(asNode(), "dependencies")
|
||||
subprojects.each {
|
||||
def depNode = depsNode.appendNode("dependency")
|
||||
depNode.appendNode("groupId", it.group)
|
||||
depNode.appendNode("artifactId", it.name)
|
||||
depNode.appendNode("version", it.version)
|
||||
depNode.appendNode("scope", "compile")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setupRepositories(repositories)
|
||||
}
|
||||
|
||||
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
|
||||
|
||||
void setupRepositories(RepositoryHandler repositories) {
|
||||
def ENV = System.getenv()
|
||||
if (project.hasProperty("maven")) {
|
||||
repositories.maven {
|
||||
url = project.getProperty("maven")
|
||||
name = "dynamic"
|
||||
|
||||
credentials(HttpHeaderCredentials) {
|
||||
name = "Job-Token"
|
||||
value = ENV.CI_JOB_TOKEN
|
||||
}
|
||||
authentication {
|
||||
header(HttpHeaderAuthentication)
|
||||
}
|
||||
}
|
||||
}
|
||||
repositories.mavenLocal()
|
||||
}
|
||||
|
||||
subprojects.each { remapJar.dependsOn("${it.path}:remapJar") }
|
||||
|
||||
dependencies {
|
||||
afterEvaluate {
|
||||
subprojects.each {
|
||||
api project(path: ":${it.name}", configuration: "dev")
|
||||
|
||||
if (!project.hasProperty("dev_only_module") || !(it.name in project.getProperty("dev_only_module").split(", "))) {
|
||||
include it
|
||||
}
|
||||
|
||||
testmodImplementation it.sourceSets.testmod.output
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task modrinth(type: com.modrinth.minotaur.TaskModrinthUpload, dependsOn: build) {
|
||||
|
@ -104,7 +298,7 @@ task modrinth(type: com.modrinth.minotaur.TaskModrinthUpload, dependsOn: build)
|
|||
versionName = "[${project.minecraft_version}] ${version}"
|
||||
versionType = project.ext.currentType
|
||||
changelog = changelogStr
|
||||
uploadFile = remapJar
|
||||
uploadFile = file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")
|
||||
addGameVersion("${project.minecraft_version}")
|
||||
addLoader('fabric')
|
||||
if (!project.modrinth_required_dependencies.isEmpty()) {
|
||||
|
@ -156,16 +350,3 @@ curseforge {
|
|||
forgeGradleIntegration = false
|
||||
}
|
||||
}
|
||||
|
||||
ext.download = { String url, String name ->
|
||||
File file = new File("$buildDir/download/${name}.jar")
|
||||
file.parentFile.mkdirs()
|
||||
if (!file.exists()) {
|
||||
new URL(url).withInputStream { downloadStream ->
|
||||
file.withOutputStream { fileOut ->
|
||||
fileOut << downloadStream
|
||||
}
|
||||
}
|
||||
}
|
||||
return dependencies.implementation(files(file.absolutePath))
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@ stages:
|
|||
build_test:
|
||||
stage: build
|
||||
script:
|
||||
- gradle --build-cache build
|
||||
- gradle --build-cache build publish -Pmaven="$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/maven"
|
||||
- cp build/libs/* ./
|
||||
- rm *-maven.jar *-sources.jar *-sources-dev.jar
|
||||
- mv *-dev.jar dev.zip
|
||||
- mv *.jar latest.jar
|
||||
- mv dev.zip latest-dev.jar
|
||||
|
@ -29,4 +30,4 @@ deploy:
|
|||
- if: $CI_COMMIT_TAG && '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^master/'
|
||||
stage: deploy
|
||||
script:
|
||||
- gradle --build-cache build curseforge modrinth -Prelease
|
||||
- gradle --build-cache build publish curseforge modrinth -Prelease -Pmaven="$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/maven"
|
||||
|
|
Loading…
Reference in New Issue