Gradle Java Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 20: Line 20:
==Source Set==
==Source Set==
Also see: {{Internal|Gradle_Dependencies_and_Dependency_Configurations#Configurations|Dependency Configurations}}
Also see: {{Internal|Gradle_Dependencies_and_Dependency_Configurations#Configurations|Dependency Configurations}}
===The "main" Source Set===
===The "test" Source Set===
==Java Toolchain==
==Java Toolchain==



Revision as of 01:53, 28 March 2021

External

Internal

TODEPLETE

Gradle Java Plugin TODELETE

Overview

The Java plugin adds Java compilation, testing and packaging capabilities to a project. It also serves as the basis for many of the other JVM language Gradle plugins.

plugins {
  id 'java'
}

However, Java Library plugin should be used by default with Java projects instead of Java plugin. Java Library plugin extends the Java plugin, so it offers all the features of the Java plugin, plus a set of additional ones:

Java Library Plugin

The Java plugin instantiates by default two source sets ("main" and "test"). Each of these source sets has an associated compile task: compileJava (which should have been called compileMainJava) for the "main" source set and compileTestJava for the "test" source set.

Concepts

Source Set

Also see:

Dependency Configurations

The "main" Source Set

The "test" Source Set

Java Toolchain

Configuration

Various aspects related to Java compilation are set in the "java" script block:

java {
  toolchain {
    languageVersion = JavaLanguageVersion.of(11)
  }
}

Tasks

assemble

build

buildDependents

buildNeeded

check

classes

clean

compileJava

The "compileJava" task is backed by the JavaCompile type.

compileTestJava

jar

Assembles the JAR file, based on the classes and resources attached to the main source set. Depends on classes. The task is backed by the Jar type. Configuration details in:

Jar Task Type

javadoc

processResources

processTestResources

test

testClasses

Java Plugin Predefined Task Types

JavaCompile

JavaCompile exposed as "compileJava" task

Jar

Jar exposed as "jar" task

JavaExec

JavaExec