Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
payara-microのJSONシリアライザーを変更するビルドスクリプト
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'war'
ext {
jdkLevel = 1.8
encoding = 'UTF-8'
payaraVersion = '4.1.152.1'
payaraDir = "build/payara-micro"
payaraMicroJar = 'payara-micro.jar'
payaraVersionFile = file("${payaraDir}/payaraVersion")
autoDiscoverable = 'org.glassfish.jersey.internal.spi.AutoDiscoverable'
}
version = '0.1'
repositories {
mavenCentral()
}
configurations {
genson
payaraMicro
}
dependencies {
genson 'com.owlike:genson:1.3'
payaraMicro "fish.payara.extras:payara-micro:${payaraVersion}"
providedCompile 'javax:javaee-api:7.0'
providedCompile 'org.glassfish.jersey.core:jersey-server:2.19'
providedCompile configurations.genson
compile 'org.slf4j:jul-to-slf4j:1.7.12'
compile('ch.qos.logback:logback-classic:1.1.3') {
exclude module: 'slf4j-api'
}
testCompile 'junit:junit:4.12'
}
tasks.withType(JavaCompile).each {
it.sourceCompatibility = jdkLevel
it.targetCompatibility = jdkLevel
it.options.encoding = encoding
}
idea {
project {
languageLevel = jdkLevel
}
}
war {
archiveName = "${project.name}.war"
}
import java.nio.file.Files
task generateAutoDiscoverable {
def metaInf = file("${buildDir}/${name}/META-INF").toPath()
def outFile = file("${buildDir}/${name}/META-INF/${autoDiscoverable}")
def contents = $/com.owlike.genson.ext.jaxrs.JerseyAutoDiscoverable
org.glassfish.jersey.media.sse.internal.SseAutoDiscoverable
org.glassfish.jersey.server.filter.internal.ServerFiltersAutoDiscoverable
/$
outputs.files outFile
outputs.upToDateWhen {
if (outFile.exists()) {
return outFile.text == contents
} else {
return false
}
}
doLast {
if (!Files.exists(metaInf)) {
Files.createDirectories(metaInf)
}
outFile.write(contents, 'UTF-8')
}
}
task copyPayaraMicro(type: Jar, dependsOn: 'generateAutoDiscoverable') {
group = 'Payara Micro Task'
description = 'Copy payara-micro jars to build directory'
archiveName = payaraMicroJar
destinationDir = file(payaraDir)
manifest {
attributes 'Main-Class': 'fish.payara.micro.PayaraMicro',
'Bundle-SymbolicName': 'fish.payara.micro',
'Payara-Version': payaraVersion
}
inputs.file configurations.payaraMicro
from configurations.payaraMicro.collect {
it.isDirectory() ? it : zipTree(it).matching {
exclude '**/com/fasterxml/jackson/**'
exclude '**/META-INF/services/javax.ws.rs.ext.Message*'
exclude '**/META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable'
}
}
from configurations.genson.collect {
it.isDirectory() ? it : zipTree(it).matching {
exclude '**/META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable'
}
}
from(tasks.generateAutoDiscoverable.outputs.files) {
into 'META-INF/services'
}
outputs.files file("${payaraDir}/${payaraMicroJar}"), payaraVersionFile
outputs.upToDateWhen {
if (payaraVersionFile.exists()) {
return payaraVersionFile.text == payaraVersion
} else {
return false
}
}
doLast {
if (!file(payaraDir).exists()) {
file(payaraDir).mkdir()
}
payaraVersionFile.write(payaraVersion, 'UTF-8')
}
}
task stage(dependsOn: ['war', 'copyPayaraMicro']) {
doLast {
def dir = file(payaraDir).toPath()
def name = Files.list(dir).map {
it.fileName.toString()
}.filter{
it.endsWith('.jar')
}.findAny().orElse(payaraMicroJar)
println "You can run app with command..."
println "java -jar ${payaraDir}/${name} --deploy build/libs/${project.name}.war"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment