Skip to content

Instantly share code, notes, and snippets.

@naosim
Last active March 21, 2018 09:10
Show Gist options
  • Save naosim/042352e1274110a7030bdb97713779ec to your computer and use it in GitHub Desktop.
Save naosim/042352e1274110a7030bdb97713779ec to your computer and use it in GitHub Desktop.
デフォルトのjarを自作のjarに差し替える
// デフォルトのjarをアーティファクトから削除
configurations.archives.artifacts.with { archives ->
def jarArtifact
archives.each {
if (it.file =~ 'jar') {
jarArtifact = it
}
}
println "JAR to delete: ${jarArtifact}"
remove(jarArtifact)
}
/**
上位で
project.ext {
docsMavenConfig = [ includeJars: ['common'] ]
}
こんな感じの設定を想定
*/
boolean isIncludeJar(obj) {
def result = project.docsMavenConfig.includeJars.findAll { obj.toString().contains(it)}.size() > 0
println("isIncludeJar: ${obj.toString()} -> ${result}")
return result
}
// 例: fatJarを作成するタスク
task fatJar(type: Jar) {
baseName = project.name + '-all'
from {
configurations.compile.findAll { isIncludeJar(it) }.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
// fatJarをアーティファクトに登録
artifacts {
archives fatJar
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment