Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 490
St.Antario Avatar asked Dec 03 '22 18:12

St.Antario


1 Answers

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'
}
like image 176
Opal Avatar answered Feb 22 '23 22:02

Opal