Start-script for my HelloWorld Scala doesn't have correct CLASSPATH


(Kenny Yu) #1

Hi

Gradle version 2.5.

I’m trying to build a HelloWorld (Scala) with startScripts.

So in the root project (i named it gradle-test), i made the following directory structure and files

C:\Users\kennyyu\gradle-test>tree /F
Folder PATH listing
Volume serial number is 606C-96AD
C:.
│   build.gradle
│
└───src
    └───main
        └───scala
            └───hello
                    HelloWorld.scala
C:\Users\kennyyu\gradle-test>

the build.gradle is given by below

apply plugin: 'scala'
apply plugin: 'application'

mainClassName = 'hello.HelloWorld'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.scala-lang:scala-library:2.11.1'
}

the HelloWorld Scala file is given by the following

package hello

object HelloWorld {
        def main(args: Array[String]) { println("Hello World!") }
}

i tried gradle -q run

C:\Users\kennyyu\gradle-test>gradle -q run
Hello World!
C:\Users\kennyyu\gradle-test>

and it does hello world as expected.

but then i tried to create start scripts:

C:\Users\kennyyu\gradle-test>gradle  startScripts
:compileJava UP-TO-DATE
:compileScala UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:startScripts UP-TO-DATE

BUILD SUCCESSFUL

Total time: 2.77 secs
C:\Users\kennyyu\gradle-test>build\scripts\gradle-test.bat
Error: Could not find or load main class hello.HelloWorld

C:\Users\kennyyu\gradle-test>

but it didn’t suceed.

I then tried to troubleshoot by reading into the generated start-up script (wiz the gradle-test.bat i just ran) - it seems to me it tried to find the jars in the lib/ folder:

C:\Users\kennyyu\gradle-test>type build\scripts\gradle-test.bat
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem  gradle-test startup script for Windows
...
...
set CLASSPATH=%APP_HOME%\lib\gradle-test.jar;%APP_HOME%\lib\scala-library-2.11.1.jar
...
...

but indeed the “gradle startScripts” task generated some JAR in the libs/ folder, not the lib/ folder. And there isn’t the scala library jar in the libs/ folder either.

C:\Users\kennyyu\gradle-test>tree /f
Folder PATH listing
Volume serial number is 606C-96AD
C:.
│   build.gradle
│
├───.gradle
│   └───2.5
│       └───taskArtifacts
│               cache.properties
│               cache.properties.lock
│               fileHashes.bin
│               fileSnapshots.bin
│               outputFileStates.bin
│               taskArtifacts.bin
│
├───build
│   ├───classes
│   │   └───main
│   │       └───hello
│   │               HelloWorld$.class
│   │               HelloWorld.class
│   │
│   ├───libs
│   │       gradle-test.jar
│   │
│   ├───scripts
│   │       gradle-test
│   │       gradle-test.bat
│   │
│   └───tmp
│       ├───compileScala
│       └───jar
│               MANIFEST.MF
│
└───src
    └───main
        └───scala
            └───hello
                    HelloWorld.scala


C:\Users\kennyyu\gradle-test>

may i confirm whether it’s a bug? or i might have done something wrong?

thanks!

Gradle Version: 2.5
Operating System: Windows 7
Is this a regression? No