【问题标题】:How to create a fatJar using "gradle build" command如何使用“gradle build”命令创建 fatJar
【发布时间】:2020-05-28 05:46:21
【问题描述】:

请注意,我们可以使用 gradle fatJar 创建 fatJar,这里我们要使用 gradle build 命令创建 fatJar。有没有可能?

【问题讨论】:

    标签: java spring-boot maven gradle groovy


    【解决方案1】:

    您实际上有两种可能的方法:

    1) 如果您已经有一些“fatJar”任务 - 您可以在“fatJar”任务之后添加下一个配置,它将在构建命令后创建两个 jars(常规和 fat):

    artifacts {
       archives fatJar
    }
    

    fatJar - 这是你的任务名称

    2) 如果您将使用这样的配置 - fatJar 将使用常规构建命令进行构建

    jar {
       manifest {
           attributes (
                'Class-Path': configurations.compile.collect {it.getName()}.join(' '),
                'Main-Class': 'com.test.MainClassName'
           )
       }
       from {
        configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it) }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-03
      • 2018-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多