Mix Groovy and Java in one Gradle project

8 steps · about 2 h 40 min · Intermediate

  1. The Groovy Plugin (doc, Gradle docs, 25 min)

    Start with the official plugin docs. They cover joint compilation, the source layout and the GroovyCompile task.

  2. JavaAndGroovy: Example project using both Groovy and Java interchangeably (article, GitHub (nickmcdowall), 20 min)

    A small working example with Gradle and Maven builds, where each language extends the other's classes.

  3. How to compile groovy sources mixed with java sources? (article, Gradle Forums, 10 min)

    Explains the stub-then-javac process behind joint compilation, and why a Java class in src/main/java can't see Groovy classes.

  4. How to compile Groovy before Java in a Gradle Build (blog, Dan Vega, 15 min)

    Walks through the common 'package does not exist' failure and fixes it by changing the source directories.

  5. Groovy Java Interoperability: 12 Proven Examples (article, Technoscripts, 30 min)

    Shows joint compilation, type coercion and the embedding options side by side, so you can compare the approaches.

  6. Integrating Groovy into Java Applications (tutorial, Baeldung, 25 min)

    Hands-on Java code that loads and runs Groovy classes and scripts on the fly.

  7. Combining Groovy and Java (tutorial, DEV Community (Tomer Figenblat), 15 min)

    A realistic use case: a Java app that calls a Groovy script through GroovyShell and Binding.

  8. Different Flavors of Embedded Groovy in Java Apps (blog, Kelly Robinson, 20 min)

    Closes by comparing the embedding styles. It is an older post, so check the details against current docs.