在Gradle中使用带有JavaExec的Manifest jar时找不到主类

时间:2015-07-04 07:43:47

标签: gradle build.gradle jhipster gatling

我有Jhipster框架中的以下gradle脚本。它用于运行Gatling测试,由于Windows上的命令行限制,我尝试使用仅清单jar方法。有关此问题的详细讨论可在此处找到Jhipster issue  但是下面的脚本似乎正确地生成了Manifest jar,但是JavaExec无法找到主类,一些指针就可以了。错误的控制台日志也在下面

我已在gradle论坛here上发布此内容,但到目前为止没有运气

申请插件:'scala'

sourceSets {
    test {
        scala {
            srcDirs = ['src/test/gatling/simulations']
            output.classesDir = 'target/test-classes'
        }
    }
}
task manifestJar(dependsOn:'compileTestScala',type: Jar) {
    dependsOn configurations.runtime
    classifier 'pathing'
    doFirst {
        manifest {
            // uri is just needed for Windows-compatibility
            attributes 'Class-Path': configurations.runtime.files.collect{ project.uri(it) }.join(' ')
        }
    }
}
task gatlingRun(dependsOn:'manifestJar', type: JavaExec) {
    //dependsOn configurations.runtime
    group = "gatling"

    standardInput = System.in

    final def sourceSet = sourceSets.test
    File configFile = file('src/test/gatling/conf/gatling.conf')

    def String gatlingDataFolder = "$project.rootDir.absolutePath/src/test/gatling/data"
    def String gatlingReportsFolder = "$project.buildDir.absolutePath/reports/gatling"
    def String gatlingBodiesFolder = "$project.rootDir.absolutePath/src/test/gatling/bodies"
    def String gatlingSimulationsFolder = "$project.rootDir.absolutePath/src/test/gatling/simulations"

    //classpath sourceSet.output + sourceSet.runtimeClasspath + files("src/test/gatling/conf")
    classpath sourceSet.output + files(manifestJar.archivePath) + files("src/test/gatling/conf")
    //classpath = files(pathingJar.archivePath)
    main = "io.gatling.app.Gatling"

    environment GATLING_HOME:''

    args '-df', gatlingDataFolder
    args '-rf', gatlingReportsFolder
    args '-bdf', gatlingBodiesFolder
    args "-sf", gatlingSimulationsFolder
    args "-rd", ""

}

控制台日志:

:compileTestJava UP-TO-DATE
:compileTestJava (Thread[main,5,main]) completed. Took 0.973 secs.
:compileTestScala (Thread[main,5,main]) started.
:compileTestScala
Skipping task ':compileTestScala' as it is up-to-date (took 0.325 secs).
:compileTestScala UP-TO-DATE
:compileTestScala (Thread[main,5,main]) completed. Took 0.344 secs.
:manifestJar (Thread[main,5,main]) started.
:manifestJar
Skipping task ':manifestJar' as it is up-to-date (took 0.012 secs).
:manifestJar UP-TO-DATE
:manifestJar (Thread[main,5,main]) completed. Took 0.038 secs.
:processTestResources (Thread[main,5,main]) started.
:processTestResources
Skipping task ':processTestResources' as it is up-to-date (took 0.013 secs).
:processTestResources UP-TO-DATE
:processTestResources (Thread[main,5,main]) completed. Took 0.041 secs.
:testClasses (Thread[main,5,main]) started.
:testClasses
Skipping task ':testClasses' as it has no actions.
:testClasses UP-TO-DATE
:testClasses (Thread[main,5,main]) completed. Took 0.019 secs.
:gatlingRun (Thread[main,5,main]) started.
:gatlingRun
Executing task ':gatlingRun' (up-to-date check took 0.001 secs) due to:
  Task has not declared any outputs.
Starting process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe''. Working directory: D:\Projects\jh5 Command: C:\Program Files\Java\jdk1.8.
0_45\bin\java.exe -Dfile.encoding=windows-1252 -Duser.country=SG -Duser.language=en -Duser.variant -cp D:\Projects\jh5\target\test-classes;D:\Projects
\jh5\build\resources\test;D:\Projects\jh5\build\libs\jhipster-pathing.jar;D:\Projects\jh5\src\test\gatling\conf io.gatling.app.Gatling -df D:\Projects
\jh5/src/test/gatling/data -rf D:\Projects\jh5\build/reports/gatling -bdf D:\Projects\jh5/src/test/gatling/bodies -sf D:\Projects\jh5/src/test/gatling
/simulations -rd
Successfully started process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe''
Error: Could not find or load main class io.gatling.app.Gatling
:gatlingRun FAILED
:gatlingRun (Thread[main,5,main]) completed. Took 0.166 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gatlingRun'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

Total time: 28.134 secs
Stopped 0 compiler daemon(s).

1 个答案:

答案 0 :(得分:3)

编辑: 您的清单jar包含错误的类路径。尝试使用testCompile个文件:

task manifestJar(dependsOn:'compileTestScala',type: Jar) {
dependsOn configurations.testCompile
archiveName 'gatlingBooter.jar'
doFirst {
    manifest {
        // uri is just needed for Windows-compatibility
        attributes 'Class-Path': configurations.testCompile.files.collect{ project.uri(it) }.join(' ')
       }
   }
}

OLD:

如果清单jar只能运行java -jar @Deepu,我们可以尝试以下方法:

task runJar(dependsOn:jar) << {
  javaexec { main="-jar"; args jar.archivePath } 
}

至少它看起来不错。将在周末尝试测试。

参考文献: