您的足迹:首页 > 语言程序 >Using Gradle to build a jar with dependencies

Using Gradle to build a jar with dependencies

The answer by @felix almost brought me there. I had two issues:

  1. With Gradle 1.5, the manifest tag was not recognised inside the fatJar task, so the Main-Class attribute could not directly be set

  2. the jar had conflicting external META-INF files.

The following setup resolves this

jar {
  manifest {
    attributes(
      'Main-Class': 'my.project.main',
    )
  }
}

task fatJar(type: Jar) {
  manifest.from jar.manifest
  classifier = 'all'
  from {
    configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
  } {
        exclude "META-INF/*.SF"
        exclude "META-INF/*.DSA"
        exclude "META-INF/*.RSA"
  }
  with jar
}

To add this to the standard assemble or build task, add:

artifacts {
    archives fatJar
}

出自http://stackoverflow.com/questions/4871656/using-gradle-to-build-a-jar-with-dependencies#

本博客所有文章如无特别注明均为原创。作者:nevergreen复制或转载请以超链接形式注明转自
原文地址《Using Gradle to build a jar with dependencies

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)