Gradle实现与jar任务中的编译

Gradle实现与jar任务中的编译,jar,build.gradle,executable-jar,Jar,Build.gradle,Executable Jar,我可以成功地使用Gradle编译胖JAR,但在最近从“compile”依赖规范切换到“implementation/api”规范后,运行JAR时遇到了问题。我已经指出,问题只发生在以下两种情况中的一种。该应用程序在IntelliJ中运行 第一个问题: dependencies {implementation 'no.tornado:tornadofx:1.7.18'} 第二/工程: dependencies {compile'no.tornado:tornadofx:1.7.18'} JAR

我可以成功地使用Gradle编译胖JAR,但在最近从“compile”依赖规范切换到“implementation/api”规范后,运行JAR时遇到了问题。我已经指出,问题只发生在以下两种情况中的一种。该应用程序在IntelliJ中运行

第一个问题:

dependencies {implementation 'no.tornado:tornadofx:1.7.18'}
第二/工程:

dependencies {compile'no.tornado:tornadofx:1.7.18'}
JAR在这两种情况下都可以编译。当我试图在命令行上启动第一个case JAR时,问题出现了,它抛出了以下错误

C:\aaa\u eric\code\testr\mic\build\libs>java-jar mic-1.0-snapshot.jar 错误:无法找到或加载主类app.MyApp 原因:java.lang.NoClassDefFoundError:tornadofx/App

下面是build.gradle中的JAR任务。tornadofx依赖项是否可能在编译时可用,但在运行时不可用?谢谢你的帮助

jar {
  manifest {
    attributes 'Main-Class': 'app.MyApp'
  }
  from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

configurations.compile.collect
更改为
configurations.compileClasspath.collect
为我修复了这个问题

我也遇到了同样的问题,并在以下几点上偶然发现了这一点:

显示如何在中按名称引用给定配置的示例 获取所有依赖项的顺序(例如JAR,但仅限于)


需要注意的一点是,
configurations.compileClasspath.collect
对我有效,即使我使用
compile
规范而不是
implement
更改
配置。compile.collect
配置。compileClasspath.collect
为我解决了这个问题

我也有同样的问题,在以下方面偶然发现了:

显示如何在中按名称引用给定配置的示例 获取所有依赖项的顺序(例如JAR,但仅限于)

需要注意的一点是,
configurations.compileClasspath.collect
即使在我使用
compile
规范而不是
implement
时,也对我有效

apply plugin: 'java' //so that I can use 'implementation', 'compileClasspath' configuration

dependencies {
    implementation 'org.slf4j:slf4j-api:1.7.26'
}

//copying all dependencies attached to 'compileClasspath' into a specific folder
task copyAllDependencies(type: Copy) {
    //referring to the 'compileClasspath' configuration
    from configurations.compileClasspath
    into 'allLibs'
}