Skip to content

Commit

Permalink
maven publish buildscript update
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchej123 committed Jan 18, 2022
1 parent fbaaed0 commit 8693f56
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 50 deletions.
16 changes: 3 additions & 13 deletions .github/workflows/release-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,8 @@ jobs:
title: "${{ env.RELEASE_VERSION }}"
files: build/libs/*.jar

- name: Set repository owner and name
run: |
echo "REPOSITORY_OWNER=${GITHUB_REPOSITORY%/*}" >> $GITHUB_ENV
echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- name: Publish package
- name: Publish to Maven
run: ./gradlew publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARTIFACT_GROUP_ID: com.github.${{ env.REPOSITORY_OWNER }}
ARTIFACT_ID: "${{ env.REPOSITORY_NAME }}"
ARTIFACT_VERSION: "${{ env.RELEASE_VERSION }}"
REPOSITORY_NAME: "${{ env.REPOSITORY_NAME }}"
REPOSITORY_OWNER: "${{ env.REPOSITORY_OWNER }}"

MAVEN_USER: ${{ secrets.MAVEN_USER }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
3 changes: 3 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Any Github changes require admin approval
/.github/** @GTNewHorizons/admin

139 changes: 102 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//version: 928ecf7feb33a1149538b0e2cd17e3bc5f281428
//version: 1642484596
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Please check https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle for updates.
Please check https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle for updates.
*/


Expand Down Expand Up @@ -32,7 +32,7 @@ buildscript {
}
}
dependencies {
classpath 'com.github.GTNewHorizons:ForgeGradle:1.2.4'
classpath 'com.github.GTNewHorizons:ForgeGradle:1.2.5'
}
}

Expand All @@ -42,6 +42,7 @@ plugins {
id("org.ajoberstar.grgit") version("3.1.1")
id("com.github.johnrengelman.shadow") version("4.0.4")
id("com.palantir.git-version") version("0.12.3")
id("maven-publish")
}

apply plugin: 'forge'
Expand Down Expand Up @@ -87,6 +88,7 @@ checkPropertyExists("containsMixinsAndOrCoreModOnly")
checkPropertyExists("usesShadowedDependencies")
checkPropertyExists("developmentEnvironmentUserName")

boolean noPublishedSources = project.findProperty("noPublishedSources") ? project.noPublishedSources.toBoolean() : false

String javaSourceDir = "src/main/java/"
String scalaSourceDir = "src/main/scala/"
Expand Down Expand Up @@ -150,12 +152,16 @@ configurations.all {

// Fix Jenkins' Git: chmod a file should not be detected as a change and append a '.dirty' to the version
'git config core.fileMode false'.execute()
// Pulls version from git tag

// Pulls version first from the VERSION env and then git tag
String identifiedVersion
try {
version = minecraftVersion + "-" + gitVersion()
String versionOverride = System.getenv("VERSION") ?: null
identifiedVersion = versionOverride == null ? gitVersion() : versionOverride
version = minecraftVersion + "-" + identifiedVersion
}
catch (Exception e) {
throw new IllegalStateException("This mod must be version controlled by Git AND the repository must provide at least one tag!");
throw new IllegalStateException("This mod must be version controlled by Git AND the repository must provide at least one tag, or the VERSION override must be set!");
}

group = modGroup
Expand Down Expand Up @@ -194,7 +200,9 @@ if(file("addon.gradle").exists()) {
apply from: 'repositories.gradle'

configurations {
implementation.extendsFrom(shadowImplementation)
implementation.extendsFrom(shadowImplementation) // TODO: remove after all uses are refactored
implementation.extendsFrom(shadowCompile)
implementation.extendsFrom(shadeCompile)
}

repositories {
Expand All @@ -220,15 +228,15 @@ dependencies {
annotationProcessor("com.google.code.gson:gson:2.8.6")
annotationProcessor("org.spongepowered:mixin:0.8-SNAPSHOT")
// using 0.8 to workaround a issue in 0.7 which fails mixin application
compile("org.spongepowered:mixin:0.7.11-SNAPSHOT") {
compile("com.github.GTNewHorizons:SpongePoweredMixin:0.7.12-GTNH") {
// Mixin includes a lot of dependencies that are too up-to-date
exclude module: "launchwrapper"
exclude module: "guava"
exclude module: "gson"
exclude module: "commons-io"
exclude module: "log4j-core"
}
compile("com.github.GTNewHorizons:SpongeMixins:1.3.3:dev")
compile("com.github.GTNewHorizons:SpongeMixins:1.5.0")
}
}

Expand Down Expand Up @@ -260,16 +268,28 @@ task relocateShadowJar(type: ConfigureShadowRelocation) {
}

shadowJar {
project.configurations.shadeCompile.each { dep ->
from(project.zipTree(dep)) {
exclude 'META-INF', 'META-INF/**'
}
}

manifest {
attributes(getManifestAttributes())
}

minimize() // This will only allow shading for actually used classes
configurations = [project.configurations.shadowImplementation]
configurations = [project.configurations.shadowImplementation, project.configurations.shadowCompile]
dependsOn(relocateShadowJar)
}

jar {
project.configurations.shadeCompile.each { dep ->
from(project.zipTree(dep)) {
exclude 'META-INF', 'META-INF/**'
}
}

manifest {
attributes(getManifestAttributes())
}
Expand Down Expand Up @@ -343,31 +363,31 @@ tasks.withType(JavaExec).configureEach {
}

processResources
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version

// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'

// replace version and mcversion
expand "minecraftVersion": project.minecraft.version,
"modVersion": versionDetails().lastTag,
"modId": modId,
"modName": modName
}
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version

if(usesMixins.toBoolean()) {
from refMap
}
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'

// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
// replace version and mcversion
expand "minecraftVersion": project.minecraft.version,
"modVersion": versionDetails().lastTag,
"modId": modId,
"modName": modName
}

if(usesMixins.toBoolean()) {
from refMap
}

// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}

def getManifestAttributes() {
def manifestAttributes = [:]
Expand Down Expand Up @@ -400,6 +420,12 @@ task sourcesJar(type: Jar) {
}

task shadowDevJar(type: ShadowJar) {
project.configurations.shadeCompile.each { dep ->
from(project.zipTree(dep)) {
exclude 'META-INF', 'META-INF/**'
}
}

from sourceSets.main.output
getArchiveClassifier().set("dev")

Expand All @@ -408,7 +434,7 @@ task shadowDevJar(type: ShadowJar) {
}

minimize() // This will only allow shading for actually used classes
configurations = [project.configurations.shadowImplementation]
configurations = [project.configurations.shadowImplementation, project.configurations.shadowCompile]
}

task relocateShadowDevJar(type: ConfigureShadowRelocation) {
Expand All @@ -423,6 +449,12 @@ task circularResolverJar(type: Jar) {
}

task devJar(type: Jar) {
project.configurations.shadeCompile.each { dep ->
from(project.zipTree(dep)) {
exclude 'META-INF', 'META-INF/**'
}
}

from sourceSets.main.output
getArchiveClassifier().set("dev")

Expand Down Expand Up @@ -453,13 +485,46 @@ task apiJar(type: Jar) {
}

artifacts {
archives sourcesJar
if(!noPublishedSources) {
archives sourcesJar
}
archives devJar
if(apiPackage) {
archives apiJar
}
}

// publishing
publishing {
publications {
maven(MavenPublication) {
artifact source: usesShadowedDependencies.toBoolean() ? shadowJar : jar, classifier: ""
if(!noPublishedSources) {
artifact source: sourcesJar, classifier: "src"
}
artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev"
if (apiPackage) {
artifact source: apiJar, classifier: "api"
}

groupId = System.getenv("ARTIFACT_GROUP_ID") ?: "com.github.GTNewHorizons"
artifactId = System.getenv("ARTIFACT_ID") ?: project.name
// Using the identified version, not project.version as it has the prepended 1.7.10
version = System.getenv("RELEASE_VERSION") ?: identifiedVersion
}
}

repositories {
maven {
url = "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases"
credentials {
username = System.getenv("MAVEN_USER") ?: "NONE"
password = System.getenv("MAVEN_PASSWORD") ?: "NONE"
}
}
}
}

// Updating
task updateBuildScript {
doLast {
Expand All @@ -478,7 +543,7 @@ if (isNewBuildScriptVersionAvailable(projectDir.toString())) {
}

static URL availableBuildScriptUrl() {
new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle")
new URL("https://raw.githubusercontent.com/GTNewHorizons/ExampleMod1.7.10/main/build.gradle")
}

boolean performBuildScriptUpdate(String projectDir) {
Expand Down Expand Up @@ -520,7 +585,7 @@ configure(updateBuildScript) {

def checkPropertyExists(String propertyName) {
if (project.hasProperty(propertyName) == false) {
throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/gradle.properties")
throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/gradle.properties")
}
}

Expand Down

0 comments on commit 8693f56

Please sign in to comment.