简体   繁体   中英

Is it possible to combine java and groovy sources in the gradle project?

I have the following project structure:

src
|
|--main
    |
    |--java
    |    |
    |    |--p
    |       |--S.java
    |  
    |
    |--groovy
         |
         |--p
            |--Main.groovy

the thing I want learn is how to combine java and groovy compiled classes together. Imagine that S.java contains the following:

package p;

public class S {
    public static void p() {
        System.out.println("p");
    }
}

and Main.groovy:

package p

public class Main {
    public static void main(String[] args) {
        S.p
    }
}

Now, the build script I've written is the simplest and contains merely

apply plugin : 'groovy'

What I want to achieve by the command build gradle is to get a jar file to using with JVM. But instead I got the following error:

Cannot infer Groovy class path because no Groovy Jar was found on class path: co
nfiguration ':compile'

Could you possibly help me to fix that error?

Applying groovy plugin gives You tasks for groovy compilation and docs etc., but does not provide dependency for groovy itself so what You're missing is:

apply plugin: 'groovy'

repositories {
   mavenCentral()
}

dependencies {
   compile 'org.codehaus.groovy:groovy:2.3.7'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM