Gradle Groovy Plugin: Difference between revisions
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | =External= | ||
* https://docs.gradle.org/current/userguide/groovy_plugin.html | * https://docs.gradle.org/current/userguide/groovy_plugin.html | ||
* Gradle in Action Section 11.2.2 "Building Groovy projects" | |||
=Internal= | =Internal= | ||
* [[Gradle_Plugin_Concepts#Core_Plugins|Gradle Plugins]] | * [[Gradle_Plugin_Concepts#Core_Plugins|Gradle Plugins]] | ||
Line 23: | Line 25: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= | The project follows the conventions introduced by the Java plugin: | ||
<syntaxhighlight lang='text'> | |||
. | |||
└─ src | |||
├─ main | |||
│ ├─ java | |||
│ ├─ groovy | |||
│ └─ resources | |||
└─ test | |||
├─ java | |||
├─ groovy | |||
└─ resources | |||
</syntaxhighlight> | |||
Java and Groovy classes can coexist in the same project, and Java classes can even depend on Groovy classes through joint compilation, which allows you to freely mix Java and Groovy source code with bidirectional dependencies on each other. This can be achieved by placing Java code together with the Groovy source code in 'src/main/groovy'. Alternatively, the Groovy compiler can be configured to enable joint compilation. This is enabled as follows: | |||
<syntaxhighlight lang='groovy'> | |||
sourceSets.main.java.srcDirs = [] | |||
sourceSets.main.groovy.srcDirs = ['src/main/java', 'src/main/groovy'] | |||
</syntaxhighlight> | |||
=Customization= | |||
The location of the source file directories can be changes reconfiguring source set in the same way it is done for the Java plugin: {{Internal|Gradle_Java_Plugin#Source_Set_Customization|Java_Plugin | Source Set Customization}} |
Latest revision as of 07:23, 28 March 2021
External
- https://docs.gradle.org/current/userguide/groovy_plugin.html
- Gradle in Action Section 11.2.2 "Building Groovy projects"
Internal
Overview
The Groovy plugin introduces a new "groovy" source set, and its corresponding compilation tasks "compileGroovy", "compileTestGroovy", similar to compileJava and compileTestJava. Similarly to the Java plugin, which builds upon a Java Base plugin, the Groovy builds upon a Groovy Base plugin. The Groovy plugin automatically applies the Java plugin as well, which means that the project contains a source set for Java sources, and anything else the Java plugin provides. This does not mean that Java sources are required to be present in the project.
plugins {
id 'groovy'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:3.0.7'
}
The project follows the conventions introduced by the Java plugin:
.
└─ src
├─ main
│ ├─ java
│ ├─ groovy
│ └─ resources
└─ test
├─ java
├─ groovy
└─ resources
Java and Groovy classes can coexist in the same project, and Java classes can even depend on Groovy classes through joint compilation, which allows you to freely mix Java and Groovy source code with bidirectional dependencies on each other. This can be achieved by placing Java code together with the Groovy source code in 'src/main/groovy'. Alternatively, the Groovy compiler can be configured to enable joint compilation. This is enabled as follows:
sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDirs = ['src/main/java', 'src/main/groovy']
Customization
The location of the source file directories can be changes reconfiguring source set in the same way it is done for the Java plugin: