Gradle java jar file

Gradle java jar file

Properties

The appendix part of the archive name, if any.

The base name of the archive.

The classifier part of the archive name, if any.

The extension part of the archive name.

The RegularFile where the archive is constructed. The path is simply the destinationDirectory plus the archiveFileName .

The archive name. If the name has not been explicitly set, the pattern for the name is: [archiveBaseName]-[archiveAppendix]-[archiveVersion]-[archiveClassifier].[archiveExtension]

The version part of the archive name.

Specifies whether case-sensitive pattern matching should be used.

The directory where the archive will be placed.

The Unix permissions to use for the target directories. null means that existing permissions are preserved. It is dependent on the copy action implementation whether these permissions will actually be applied.

The strategy to use when trying to copy more than one file to the same destination.

The compression level of the entries of the archive. If set to ZipEntryCompression.DEFLATED (the default), each entry is compressed using the DEFLATE algorithm. If set to ZipEntryCompression.STORED the entries of the archive are left uncompressed.

The set of exclude patterns.

The Unix permissions to use for the target files. null means that existing permissions are preserved. It is dependent on the copy action implementation whether these permissions will actually be applied.

Tells if empty target directories will be included in the copy.

The set of include patterns.

The manifest for this JAR archive.

The character set used to encode JAR metadata like file names. Defaults to UTF-8. You can change this property but it is not recommended as JVMs expect JAR metadata to be encoded using UTF-8

Specifies whether file timestamps should be preserved in the archive.

Specifies whether to enforce a reproducible file order when reading files from directories.

The source files for this task.

Whether the zip can contain more than 65535 files and/or support files greater than 4GB in size.

Methods

Adds an action to be applied to each file as it about to be copied into its destination. The given closure is called with a FileCopyDetails as its parameter. Actions are executed in the order added, and are inherited from the parent spec.

Adds an action to be applied to each file as it is about to be copied into its destination. The action can change the destination path of the file, filter the contents of the file, or exclude the file from the result entirely. Actions are executed in the order added, and are inherited from the parent spec.

Adds an exclude spec. This method may be called multiple times to append new specs.The given closure is passed a FileTreeElement as its parameter. The closure should return true or false. Example:

Adds an ANT style exclude pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

Adds an ANT style exclude pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

Adds an exclude spec. This method may be called multiple times to append new specs. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

Expands property references in each file as it is copied. More specifically, each file is transformed using Groovy’s SimpleTemplateEngine . This means you can use simple property references, such as $property or $ in the file. You can also include arbitrary Groovy code in the file, such as $ or $

Expands property references in each file as it is copied. More specifically, each file is transformed using Groovy’s SimpleTemplateEngine . This means you can use simple property references, such as $property or $ in the file. You can also include arbitrary Groovy code in the file, such as $ or $ . The template engine can be configured with the provided action.

Configure the FileCopyDetails for each file whose path matches any of the specified Ant-style patterns. This is equivalent to using eachFile() and selectively applying a configuration based on the file’s path.

Configure the FileCopyDetails for each file whose path matches the specified Ant-style pattern. This is equivalent to using eachFile() and selectively applying a configuration based on the file’s path.

Configure the FileCopyDetails for each file whose path does not match any of the specified Ant-style patterns. This is equivalent to using eachFile() and selectively applying a configuration based on the file’s path.

Configure the FileCopyDetails for each file whose path does not match the specified Ant-style pattern. This is equivalent to using eachFile() and selectively applying a configuration based on the file’s path.

Adds a content filter based on the provided closure. The Closure will be called with each line (stripped of line endings) and should return a String to replace the line or null to remove the line. If every line is removed, the result will be an empty file, not an absent one.

Adds a content filter to be used during the copy. Multiple calls to filter, add additional filters to the filter chain. Each filter should implement java.io.FilterReader . Include org.apache.tools.ant.filters.* for access to all the standard Ant filters.

Adds a content filter to be used during the copy. Multiple calls to filter, add additional filters to the filter chain. Each filter should implement java.io.FilterReader . Include org.apache.tools.ant.filters.* for access to all the standard Ant filters.

Adds a content filter based on the provided transformer. The Closure will be called with each line (stripped of line endings) and should return a String to replace the line or null to remove the line. If every line is removed, the result will be an empty file, not an absent one.

Specifies the source files or directories for a copy and creates a child CopySourceSpec . The given source path is evaluated as per Project.files(java.lang.Object[]) .

Specifies the source files or directories for a copy and creates a child CopySpec . The given source path is evaluated as per Project.files(java.lang.Object[]) .

Specifies source files or directories for a copy. The given paths are evaluated as per Project.files(java.lang.Object[]) .

Adds an include spec. This method may be called multiple times to append new specs. The given closure is passed a FileTreeElement as its parameter. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns or specs to be included.

Adds an ANT style include pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns to be processed.

Adds an ANT style include pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns to be processed.

Adds an include spec. This method may be called multiple times to append new specs. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns or specs to be included.

Specifies the destination directory *inside* the archive for the files. The destination is evaluated as per Project.file(java.lang.Object) . Don’t mix it up with AbstractArchiveTask.getDestinationDirectory() which specifies the output directory for the archive.

Creates and configures a child CopySpec with a destination directory *inside* the archive for the files. The destination is evaluated as per Project.file(java.lang.Object) . Don’t mix it up with AbstractArchiveTask.getDestinationDirectory() which specifies the output directory for the archive.

Creates and configures a child CopySpec with a destination directory *inside* the archive for the files. The destination is evaluated as per Project.file(java.lang.Object) . Don’t mix it up with AbstractArchiveTask.getDestinationDirectory() which specifies the output directory for the archive.

Configures the manifest for this JAR archive.

Configures the manifest for this JAR archive.

Adds content to this JAR archive’s META-INF directory.

Adds content to this JAR archive’s META-INF directory.

Renames a source file. The closure will be called with a single parameter, the name of the file. The closure should return a String object with a new target name. The closure may return null, in which case the original name will be used.

Renames files based on a regular expression. Uses java.util.regex type of regular expressions. Note that the replace string should use the ‘$1’ syntax to refer to capture groups in the source regular expression. Files that do not match the source regular expression will be copied with the original name.

Renames a source file. The function will be called with a single parameter, the name of the file. The function should return a new target name. The function may return null, in which case the original name will be used.

Adds the given specs as a child of this spec.

Источник

Building Java Libraries Sample

This guide demonstrates how to create a Java library with Gradle using gradle init . You can follow the guide step-by-step to create a new project from scratch or download the complete sample project using the links above.

What you’ll build

You’ll generate a Java library that follows Gradle’s conventions.

What you’ll need

  • A text editor or IDE — for example IntelliJ IDEA
  • A Java Development Kit (JDK), version 8 or higher — for example AdoptOpenJDK
  • The latest Gradle distribution

Create a project folder

Gradle comes with a built-in task, called init , that initializes a new Gradle project in an empty folder. The init task uses the (also built-in) wrapper task to create a Gradle wrapper script, gradlew .

The first step is to create a folder for the new project and change directory into it.

Run the init task

From inside the new project directory, run the init task using the following command in a terminal: gradle init . When prompted, select the 3: library project type and 3: Java as implementation language. Next you can choose the DSL for writing buildscripts — 1 : Groovy or 2: Kotlin . For the other questions, press enter to use the default values.

The output will look like this:

$ gradle init Select type of project to generate: 1: basic 2: application 3: library 4: Gradle plugin Enter selection (default: basic) [1..4] 3 Select implementation language: 1: C++ 2: Groovy 3: Java 4: Kotlin 5: Scala 6: Swift Enter selection (default: Java) [1..6] 3 Select build script DSL: 1: Groovy 2: Kotlin Enter selection (default: Groovy) [1..2] 1 Select test framework: 1: JUnit 4 2: TestNG 3: Spock 4: JUnit Jupiter Enter selection (default: JUnit 4) [1..4] Project name (default: demo): Source package (default: demo): BUILD SUCCESSFUL 2 actionable tasks: 2 executed

The init task generates the new project with the following structure:

├── gradle (1) │ └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew (2) ├── gradlew.bat (2) ├── settings.gradle.kts (3) └── lib ├── build.gradle.kts (4) └── src ├── main │ └── java (5) │ └── demo │ └── Library.java └── test └── java (6) └── demo └── LibraryTest.java
├── gradle (1) │ └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew (2) ├── gradlew.bat (2) ├── settings.gradle (3) └── lib ├── build.gradle (4) └── src ├── main │ └── java (5) │ └── demo │ └── Library.java └── test └── java (6) └── demo └── LibraryTest.java
1 Generated folder for wrapper files
2 Gradle wrapper start scripts
3 Settings file to define build name and subprojects
4 Build script of lib project
5 Default Java source folder
6 Default Java test source folder

You now have the project setup to build a Java library.

Review the project files

The settings.gradle(.kts) file has two interesting lines:

rootProject.name = "demo" include("lib")

Источник

Читайте также:  Свой компонент битрикс class php
Оцените статью