forked from RetroGradle/MCPConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_template.gradle
91 lines (80 loc) · 3.03 KB
/
project_template.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
import groovy.xml.*
repositories {
//mavenCentral() //TODO: Update Gradle to use HTTPS by default
maven {
name 'maven_central'
url 'https://repo.maven.apache.org/maven2/'
}
maven {
name 'minecraft'
url 'https://libraries.minecraft.net/'
}
maven {
name 'forge'
url 'https://files.minecraftforge.net/maven/'
}
}
configurations.all {
transitive = false
}
dependencies {
{libraries}
}
ext {
DISTRO = '{distro}'
INJECT = {inject}
ASSETS = {assets}
NATIVES = {natives}
}
if (INJECT != null) {
sourceSets.create('pkginfo')
sourceSets.create('inject') {
java {
srcDir INJECT
exclude 'package-info-template.java'
if (DISTRO == 'server')
exclude '**/client/**/*'
else
exclude '**/server/**/*'
}
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}
compileJava.sourceCompatibility = compileJava.targetCompatibility = sourceCompatibility = targetCompatibility = '1.8'
eclipseClasspath.doLast { t ->
def xml = new XmlParser().parse(t.outputFile)
println t.outputFile
xml.classpathentry.findAll{ it.attributes().kind == 'src' }.each { e ->
if (e.get('attributes').isEmpty()) e.appendNode('attributes')
if (e.'attributes'[0].attribute.findAll{it.attributes().name == 'org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY'}.isEmpty())
e.'attributes'[0]?.appendNode('attribute', [name: 'org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY', value: NATIVES])
}
def order = ['src', 'output', 'con', 'lib']
xml.children().sort { order.contains(it.@kind) ? order.indexOf(it.@kind) : order.size() + 1 }
t.outputFile.text = XmlUtil.serialize(xml)
def workdir = file('../run')
if (!workdir.exists())
workdir.mkdirs()
(DISTRO == 'server' ? ['server'] : DISTRO == 'client' ? ['client'] : ['server', 'client']).each { side ->
def writer = new StringWriter()
xml = new MarkupBuilder(writer)
xml.launchConfiguration(type: 'org.eclipse.jdt.launching.localJavaApplication') {
stringAttribute(key: 'org.eclipse.jdt.launching.MAIN_TYPE', value: side == 'server' ? 'net.minecraft.server.MinecraftServer' : 'mcp.client.Start')
stringAttribute(key: 'org.eclipse.jdt.launching.PROJECT_ATTR', value: project.name)
stringAttribute(key: 'org.eclipse.jdt.launching.WORKING_DIRECTORY', value: workdir.absolutePath)
if (side != 'server') {
mapAttribute(key: 'org.eclipse.debug.core.environmentVariables') {
mapEntry(key: 'assetDirectory', value: ASSETS)
}
}
}
file("Run${DISTRO.capitalize()}${side.capitalize()}.launch").text = writer.toString()
}
}
eclipse.classpath.file {
beforeMerged { it.entries.removeAll { entry -> entry.kind == 'src' } }
}