Files
HMCL/HMCL/build.gradle
2016-08-18 11:25:03 +08:00

205 lines
6.1 KiB
Groovy
Executable File

/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
buildscript {
repositories {
mavenCentral();
maven {
url "https://libraries.minecraft.net"
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:4.10'
classpath 'edu.sc.seis.gradle:launch4j:1.0.6'
classpath 'me.tatarka:gradle-retrolambda:3.1.0'
classpath 'com.google.code.gson:gson:2.2.4'
}
}
}
plugins {
id "edu.sc.seis.macAppBundle" version "2.1.6"
}
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import com.google.gson.JsonParser
apply plugin: 'launch4j'
apply plugin: 'me.tatarka.retrolambda'
if (!hasProperty('mainClass')) {
ext.mainClass = 'org.jackhuang.hellominecraft.launcher.Main'
}
def readBuildNumber() {
def versionPropsFile = file('version.properties')
def Properties versionProps = new Properties()
if (versionPropsFile.canRead()) {
versionProps.load(new FileInputStream(versionPropsFile))
def code = versionProps['VERSION_CODE'].toInteger()
return code.toString()
} else {
versionPropsFile.createNewFile()
String url = 'https://api.travis-ci.org/repos/mclauncher/HMCL/branches'
def json = new JsonParser().parse(url.toURL().text);
if (json.has('branches') && json.get('branches').isJsonArray()) {
def branches = json.getAsJsonArray('branches')
if (branches != null && branches.size() > 0) {
def info = branches.get(0).getAsJsonObject()
def code = info.get('number').getAsInt().toString()
versionProps['VERSION_CODE'] = code
versionProps.store(versionPropsFile.newWriter(), null)
return code
}
}
}
return '233'
}
task cleanVersionFile << {
file("version.properties").delete()
}
def buildnumber = System.getenv("TRAVIS_BUILD_NUMBER")
if (buildnumber == null)
buildnumber = System.getenv("BUILD_NUMBER")
if (buildnumber == null)
buildnumber = readBuildNumber()
def versionroot = System.getenv("VERSION_ROOT")
if (versionroot == null)
versionroot = "2.5.1"
String mavenGroupId = 'HMCL'
String mavenVersion = versionroot + '.' + buildnumber
String bundleName = "Hello Minecraft! Launcher"
group = mavenGroupId
version = mavenVersion
String mavenArtifactId = name
task generateSources(type: Copy) {
from 'src/main/java'
from 'src/core/java'
into "$buildDir/generated-src"
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
'HELLO_MINECRAFT_LAUNCHER_VERSION_FOR_GRADLE_REPLACING': mavenVersion
])
}
compileJava.setSource "$buildDir/generated-src"
compileJava.dependsOn generateSources
task macAppCompressed(type: Zip, dependsOn: createApp) {
archiveName "HMCL-$mavenVersion-MacOSApp.zip"
include '**'
destinationDir file("$buildDir/libs/")
from "$buildDir/macApp"
}
macAppBundle {
mainClassName = mainClass
icon = "src/main/icon.icns"
javaProperties.put("apple.laf.useScreenMenuBar", "true")
}
sourceSets {
main {
java {
srcDirs = [
'src/core/java/',
'src/main/java/'
]
}
resources {
srcDirs = ['src/main/resources/']
}
}
core {
java {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
srcDirs 'src/core/java/'
}
resources {
srcDirs 'src/main/resources/'
}
}
}
configurations {
coreCompile.extendsFrom compile
coreRuntime.extendsFrom runtime
}
configure(install.repositories.mavenInstaller) {
pom.project {
groupId = mavenGroupId
artifactId = mavenArtifactId
version = mavenVersion
}
}
dependencies {
compile project(":HMCLaF")
compile project(":HMCUtils")
compile group: "org.commonjava.googlecode.markdown4j", name: "markdown4j", version: "2.2-cj-1.0"
}
retrolambda {
javaVersion = JavaVersion.VERSION_1_6
}
jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes 'Created-By' : 'Copyright(c) 2013-2016 HMCLSoft.',
'Main-Class' : mainClass
}
}
launch4j {
supportUrl = 'http://www.hmclsoft.com'
jreMinVersion = '1.6.0'
mainClassName = mainClass
icon = new File(project.buildDir, '../icon.ico').absolutePath
version = mavenVersion
downloadUrl = 'http://java.com/download'
copyright = "Copyright(c) 2013-2016 HMCLSoft."
jar = new File(project.buildDir, 'libs/' + mavenGroupId + '-' + mavenVersion + '.jar').absolutePath
outfile = mavenGroupId + '-' + mavenVersion + '.exe'
messagesJreVersionError = 'This application requires a Java Runtime Environment installation, or the runtime is corrupted.\n\u6ca1\u6709\u627e\u5230\u004a\u0061\u0076\u0061\u8fd0\u884c\u65f6\uff0c\u8bf7\u4e0d\u8981\u4f7f\u7528\u7eff\u8272\u004a\u0061\u0076\u0061\uff0c\u8bf7\u4f7f\u7528\u5b89\u88c5\u7248\u7684\u004a\u0061\u0076\u0061\uff0c\u70b9\u51fb\u786e\u5b9a\u8fdb\u5165\u004a\u0061\u0076\u0061\u5b89\u88c5\u9875\u9762\u3002'
}
processResources {
from(sourceSets.main.resources.srcDirs) {
exclude 'icon.icns'
}
}
build.dependsOn cleanVersionFile
build.dependsOn makeExecutable
build.dependsOn makePackGZ
build.dependsOn macAppCompressed