Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Gradle.pdf
Скачиваний:
9
Добавлен:
24.03.2015
Размер:
1.4 Mб
Скачать

Example 23.13. Separate MANIFEST.MF for a particular archive build.gradle

task barJar(type: Jar) { manifest {

attributes key1: 'value1'

from sharedManifest, 'src/config/basemanifest.txt' from('src/config/javabasemanifest.txt', 'src/config/libbasemanifest.tx

eachEntry { details ->

if (details.baseValue != details.mergeValue) { details.value = baseValue

}

if (details.key == 'foo') { details.exclude()

}

}

}

}

}

Manifest are merged in the order they are declared by the from statement. If the based manifest and the merged manifest both define values for the same key, the merged manifest wins by default. You can fully customize the merge behavior by adding eachEntry actions in which you have access to a ManifestMergeDetails instance for each entry of the resulting manifest. The merge is not immediately triggered by the from statement. It is done lazily, either when generating the jar, or by calling writeTo or effectiveManifest

You can easily write a manifest to disk.

Example 23.14. Separate MANIFEST.MF for a particular archive

build.gradle

jar.manifest.writeTo("$buildDir/mymanifest.mf")

23.14. Uploading

How to upload your archives is described in Chapter 44, Publishing artifacts.

Page 155 of 343

24

The Groovy Plugin

The Groovy plugin extends the Java plugin to add support for Groovy projects. It can deal with Groovy-only projects and with mixed Java/Groovy projects. It can even deal with Java-only projects. [9] The Groovy plugin supports joint compilation of Java and Groovy. This means that your project can contain Groovy classes which use Java classes, and vice versa.

24.1. Usage

To use the Groovy plugin, include in your build script:

Example 24.1. Using the Groovy plugin

build.gradle

apply plugin: 'groovy'

24.2. Tasks

The Groovy plugin adds the following tasks to the project.

Page 156 of 343

[10]

Table 24.1. Groovy plugin - tasks

 

 

Task name

Depends on

Type

Description

compileGroovy

compileJava

GroovyCompile

Compiles production

 

 

 

Groovy source files

 

 

 

using groovyc.

compileTestGroovy

compileTestJava

GroovyCompile

Compiles test Groovy

 

 

 

source files using

 

 

 

groovyc.

compileSourceSetGroovycompileSourceSetJaGroovyCompileva

Compiles the given

 

 

 

source set's Groovy

 

 

 

source files using

 

 

 

groovyc.

groovydoc

-

Groovydoc

Generates API

 

 

 

documentation for the

 

 

 

production Groovy

 

 

 

source files using

 

 

 

groovydoc.

The Groovy plugin adds the following dependencies to tasks added by the Java plugin.

Table 24.2. Groovy plugin - additional task dependencies

Task name

Depends on

classes

compileGroovy

testClasses

compileTestGroovy

sourceSetClasses

compileSourceSetGroovy

Figure 24.1. Groovy plugin - tasks

24.3. Project layout

The Groovy plugin assumes the project layout shown in Table 24.3, “Groovy plugin - project layou

. All the Groovy source directories can contain Groovy and Java code. The Java source directories may only contain Java source code. None of these directories need exist or have anything in them. The Groovy plugin will compile whatever it finds, and handles anything which is missing.

Page 157 of 343

Table 24.3. Groovy plugin - project layout

Directory

Meaning

src/main/java

Production Java source

src/main/resources

Production resources

src/main/groovy

Production Groovy source. May also contain Java source for joint

 

compilation.

src/test/java

Test Java source

src/test/resources

Test resources

src/test/groovy

Test Groovy source. May also contain Java source for joint

 

compilation.

src/sourceSet/java Java source for the given source set src/sourceSet/resourcesResources for the given source set

src/sourceSet/groovy Groovy source for the given source set. May also contain Java source for joint compilation.

24.3.1. Changing the project layout

TBD

Example 24.2. Custom Groovy source layout

build.gradle

sourceSets { main {

groovy {

srcDir 'src/groovy'

}

}

}

24.4. Dependency management

The Groovy plugin adds a dependency configuration called groovy.

Gradle is written in Groovy and allows you to write your build scripts in Groovy. But this is an internal aspect of Gradle which is strictly separated from building Groovy projects. You are free to choose the Groovy version your project should be build with. This Groovy version is not just used for compiling your code and running your tests. The groovyc compiler and the groovydoc tool are also taken from the Groovy version you provide. As usual, with freedom comes responsibility ;). You are not just free to choose a Groovy version, you have to provide one. Gradle expects that the groovy libraries are assigned to the groovy dependency configuration. Here is an example using the public Maven repository:

Page 158 of 343

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]