summaryrefslogtreecommitdiff
path: root/old-build.gradle.kts
blob: fa79c4d66483cdd86de6cfaa7bf8db545df0f5b2 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
@file:Suppress("UNUSED_VARIABLE")

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.dsl.Coroutines.ENABLE
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
import java.io.PrintWriter

val firstImport = false
val stdout = PrintWriter(File("$rootDir/gradle-output.txt"))

buildscript {
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51")
    }
}

group = "io.dico"
version = "0.1"

inline fun <reified T : Plugin<out Project>> Project.apply() =
    (this as PluginAware).apply<T>()

allprojects {
    apply<JavaPlugin>()

    repositories {
        mavenCentral()
        maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots")
        maven("https://hub.spigotmc.org/nexus/content/repositories/sonatype-nexus-snapshots")
    }
    dependencies {
        val spigotVersion = "1.13-R0.1-SNAPSHOT"
        compile("org.bukkit:bukkit:$spigotVersion") { isTransitive = false }
        compile("org.spigotmc:spigot-api:$spigotVersion") { isTransitive = false }

        compile("net.sf.trove4j:trove4j:3.0.3")
        testCompile("junit:junit:4.12")
    }
}

project(":dicore3:dicore3-command") {
    apply<KotlinPlatformJvmPlugin>()

    kotlin.experimental.coroutines = ENABLE

    dependencies {
        compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4")
        compile(kotlin("reflect", version = "1.2.50"))
        compile(kotlin("stdlib-jdk8", version = "1.2.51"))
        compile(project(":dicore3:dicore3-core"))
        compile("com.thoughtworks.paranamer:paranamer:2.8")
    }
}


plugins {
    kotlin("jvm") version "1.2.51"
    id("com.github.johnrengelman.plugin-shadow") version "2.0.3"
}

kotlin.experimental.coroutines = ENABLE

repositories {
    maven("https://dl.bintray.com/kotlin/exposed")
}

dependencies {
    compile(project(":dicore3:dicore3-core"))
    compile(project(":dicore3:dicore3-command"))
    compile(kotlin("stdlib-jdk8"))

    compile("org.jetbrains.exposed:exposed:0.10.3")
    compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4")
    compile("com.zaxxer:HikariCP:3.2.0")
    compile("com.h2database:h2:1.4.197")

    val jacksonVersion = "2.9.6"
    compile("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
    compile("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
    compile("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
    compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jacksonVersion")
    //compile("org.yaml:snakeyaml:1.19")

    compile("org.slf4j:slf4j-api:1.7.25")
    compile("ch.qos.logback:logback-classic:1.2.3")
}

tasks {
    val serverDir = "$rootDir/debug"
    val jar by getting(Jar::class)
    val kotlinStdlibJar by creating(Jar::class) {
        destinationDir = file("$serverDir/lib")
        archiveName = "kotlin-stdlib.jar"
        packageDependencies("kotlin-stdlib-jdk8")
    }

    val debugEnvironment by creating(Exec::class) {

    }

    val releaseJar by creating(ShadowJar::class) {
        destinationDir = file("$serverDir/plugins")
        baseName = "parcels2-release"

        with(jar)

        packageArtifacts(
            "jackson-core",
            "jackson-databind",
            "jackson-module-kotlin",
            "jackson-annotations",
            "jackson-dataformat-yaml",
            "snakeyaml",

            "slf4j-api",
            "logback-core",
            "logback-classic",

            //"h2",
            "HikariCP",
            "kotlinx-coroutines-core",
            "kotlinx-coroutines-core-common",
            "atomicfu-common",
            "exposed",

            "dicore3-core",
            "dicore3-command",
            "paranamer",

            "trove4j",
            "joda-time",

            "annotations",
            "kotlin-stdlib-common",
            "kotlin-stdlib",
            "kotlin-stdlib-jdk7",
            "kotlin-stdlib-jdk8",
            "kotlin-reflect"
        )

        relocate("org.yaml.snakeyaml", "io.dico.parcels2.util.snakeyaml")

        manifest.attributes["Class-Path"] = "lib/kotlin-stdlib.jar"
        dependsOn(kotlinStdlibJar)
    }

}

allprojects {
    tasks.filter { it is Jar }.forEach { it.group = "artifacts" }
}

stdout.flush()
stdout.close()

fun Jar.packageDependencies(vararg names: String) {
    if (!firstImport) {
        from(*project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies
            .filter { it.moduleName in names }
            .flatMap { it.allModuleArtifacts }
            .map { it.file }
            .map(::zipTree)
            .toTypedArray()
        )
    }
}

fun Jar.packageDependency(name: String, configure: ModuleDependency.() -> Unit) {
    if (!firstImport) {
        val configuration = project.configurations.compile.copyRecursive()

        configuration.dependencies.removeIf {
            if (it is ModuleDependency && it.name == name) {
                it.configure()
                false
            } else true
        }

        from(*configuration.resolvedConfiguration.resolvedArtifacts
            .map { it.file }
            .map(::zipTree)
            .toTypedArray())
    }
}

@Suppress("IMPLICIT_CAST_TO_ANY")
fun Jar.packageArtifacts(vararg names: String) {
    if (!firstImport) {
        from(*project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies
            .flatMap { dep -> dep.allModuleArtifacts.map { dep to it } }
            .filter { pair ->
                val (dep, art) = pair
                val id = art.moduleVersion.id
                (id.name in names).also {
                    val artName = art.moduleVersion.id.let {"${it.group}:${it.name}:${it.version}"}
                    val depName = dep.let { "${it.moduleGroup}:${it.moduleName}:${it.moduleVersion}" }
                    val name = "$artName \n    from $depName"
                    stdout.println("${if (it) "Including" else "Not including"} artifact $name")
                }
            }
            .map { pair -> pair.second.file }
            .map { if (it.isDirectory()) it else zipTree(it) }
            .toTypedArray())
    }
}