Java实现依赖关系排序_排序多个Gradle插件任务的依赖关系

Please note: 虽然我在这里特别提到了两个Gradle插件,但这是100%关于理解Gradle中任务依赖关系的问题,并且不需要任何关于单个插件的知识(我认为)!

我有一个项目将使用两个Gradle插件:

Gradle Shadow plugin,它将生成一个自包含的"fat jar"(基本上是一个包含我所有类的大jar加上我所有传递依赖的类,然后允许我只需运行 java -jar myapp.jar 而无需管理jar的外部类路径等) . 这将在 build/libs/myapp.jar 产生一个胖 jar ;和

Gradle Launch4J plugin,它使用Launch4J将jar转换为本机可执行文件(EXE等) . Obviously the fat jar has to be created prior to the Launch4J tasks run, otherwise they'll have nothing to wrap inside of an EXE!

这是我的 build.gradle :

import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer

plugins {

id 'groovy'

id 'application'

id 'maven-publish'

id 'com.github.johnrengelman.shadow' version '1.2.3'

id 'edu.sc.seis.launch4j' version '2.3.0'

}

sourceCompatibility = 1.8

targetCompatibility = 1.8

group = 'hotmeatballsoup'

mainClassName = 'com.me.myapp.Driver'

repositories {

mavenCentral()

jcenter()

}

dependencies {

compile(

'org.codehaus.groovy:groovy-all:2.4.7'

,'org.slf4j:slf4j-api:1.7.24'

,'org.slf4j:slf4j-simple:1.7.24'

)

}

manifest {

attributes 'Main-Class': mainClassName

}

jar {

manifest {

attributes 'Main-Class': mainClassName

}

baseName = 'zimbus'

}

shadowJar {

transform(ServiceFileTransformer) {

exclude 'META-INF/*.DSA'

exclude 'META-INF/*.RSA'

exclude 'LICENSE*'

}

transform(com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer) {

resource = 'reference.conf'

}

classifier = ''

}

publishing {

publications {

shadow(MavenPublication) {

from components.shadow

artifactId = 'zimbus'

}

}

}

launch4j {

outfile = 'zimbus.exe'

mainClassName = 'com.me.myapp.Driver'

icon = 'zimbus.ico'

jar = 'build/libs/gradle-launch4j-example.jar'

}

在命令行我运行:

./gradlew clean build shadowJar createAllExecutables

这里的意图是我想首先创建胖jar(在 shadowJar 运行时调用),然后启动Launch4J(在 createAllExecutables 运行时调用) . 但是当我运行它时,我得到以下异常:

:createExe FAILED

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':createExe'.

> Launch4J finished with non-zero exit value 1

launch4j: Application jar doesn't exist.

我很确定 createAllExecutables 任务在 shadowJar 任务之前被触发,因此没有任何东西(没有胖 jar )在EXE内部捆绑 .

有人可以证实我的怀疑,并帮助我定义将正确命令我的任务的 dependsOn 声明吗?或者,如果任务以正确的顺序执行,可能会提供有关导致错误的原因的任何想法?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值