ShadowJar Bookmarks

Published: 2023-01-25, Updated: 2023-02-19

Links

Artifact assemble / Gerate uber jar / Fat Jar

Configurar jar spring boot com shadow / gerar jar com dependencias

plugins {
  id "com.github.johnrengelman.shadow" version "7.1.2"
}

def mainClassName = "com.mageddo.TemplateMsApp"

jar {
  manifest {
    attributes(
      "Main-Class": mainClassName
    )
  }
}

shadowJar {
  mergeServiceFiles()
  append 'META-INF/spring.handlers'
  append 'META-INF/spring.schemas'
  append 'META-INF/spring.tooling'
  transform(com.github.jengelman.gradle.plugins.shadow.transformers.PropertiesFileTransformer) {
    paths = ['META-INF/spring.factories' ]
    mergeStrategy = "append"
  }
}
./gradlew build shadowJar

Renomear o pacote na hora de gerar jar

O proprio plugin vai alterar o pacote no codigo fonte que foi compilado tambem, mas soh no compilado

Configurado no meu projeto csv2jdbc

apply plugin: 'com.github.johnrengelman.shadow'

shadowJar {
    relocate 'com.myCompany.project.event', 'com.myCompany.relocated.project.event'
}

assemble.dependsOn shadowJar

Tirar dependencias especificas do jar que é gerado


shadowJar {
//  configurations = [project.configurations.compileClasspath]
//  configurations = [project.configurations.runtimeClasspath]
  // https://imperceptiblethoughts.com/shadow/configuration/dependencies/#filtering-dependencies
  dependencies {
    exclude(dependency('org.antlr:antlr4:'))
    exclude(dependency(':antlr-runtime:'))
    exclude(dependency(':ST4:'))
    exclude(dependency(':org.abego.treelayout.core:'))
    exclude(dependency(':javax.json:'))
    exclude(dependency(':icu4j:'))
    exclude(dependency {
      println("=>>> ${it}")
    })
  }
  relocate 'org.apache.commons.csv', 'com.mageddo.thirdparty.org.apache.commons.csv'
}

Gerar fatjar - Task customizada

task linuxBluetoothConnectionFixJar(type: ShadowJar) {

  manifest {
    attributes("Main-Class": "com.mageddo.linux.bluetoothfix.Main")
  }

  mergeServiceFiles()
  from sourceSets.main.output
  configurations = [project.configurations.runtimeClasspath]
  archiveFileName = "linux-bluetooth-connection-fix-${project.version}.jar"

  exclude("/data/**")
  exclude("/json/**")
  exclude("/META-INF/resources/**")
  exclude("/templates/**")
}

Gerar jar apenas com o código fonte - Task customizada

task liveWatcherJar(type: ShadowJar) {
  from sourceSets.main.output
  archiveFileName = "live-watcher-${project.version}.jar"
  exclude("/data/**")
  exclude("/json/**")
  exclude("/META-INF/resources/**")
  exclude("/templates/**")
}

Gerar jar apenas com as libs do projeto - Task customizada

task liveWatcherLibsJar(type: ShadowJar) {
  mergeServiceFiles()
  configurations = [project.configurations.runtimeClasspath]
  archiveFileName = "live-watcher-${project.version}-libs.jar"
}

shadow, shadowjar commands, shadow commands


Boas Práticas Programação Fixando problema de fone bluetooth no Linux

Comments