java-gradle-plugins

Collection of Gradle plugins for Java development

License

License

Categories

Categories

Java Languages Gradle Build Tools
GroupId

GroupId

de.carne
ArtifactId

ArtifactId

java-gradle-plugins
Last Version

Last Version

0.9.1
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

java-gradle-plugins
Collection of Gradle plugins for Java development
Project URL

Project URL

https://github.com/hdecarne/java-gradle-plugins
Source Code Management

Source Code Management

https://github.com/hdecarne/java-gradle-plugins.git

Download java-gradle-plugins

Dependencies

runtime (6)

Group / Artifact Type Version
jakarta.ws.rs : jakarta.ws.rs-api jar 3.0.0
org.glassfish.jersey.core : jersey-client jar 3.0.0
org.glassfish.jersey.ext : jersey-proxy-client jar 3.0.0
org.glassfish.jersey.media : jersey-media-json-jackson jar 3.0.0
org.eclipse.jgit : org.eclipse.jgit jar 5.10.0.202012080955-r
org.glassfish.jersey.inject : jersey-hk2 jar 3.0.0

Project Modules

There are no modules declared in this project.

Gradle Java-Tools plugin

Publication Build Status Coverage

This project collects custom Gradle plugins used for the development of my private projects.

Plugin de.carne.java-tools

See plugins.gradle.org for how enable the plugin in your build script.

The fastest way is the Gradle plugin mechanism:

plugins {
	id 'de.carne.java-tools' version 'latest.version'
}

Check the badge above to determine the latest version of the plugin.

Task generateI18N

This task runs automatically before the compileJava task, scans the source set for existing resource bundles and generates access classes for them. The following default settings are used by this task.

javatools {
	generateI18N {
		enabled = true
		keyFilter = "^I18N_.*"
		genDir = file("src/main/java")
		bundles = fileTree("src/main/resources") {
			include "**/*I18N.properties"
		}
}
  • enabled: Set this to false to disable the task.
  • keyFilter: Java regular expression pattern identifying the resource keys to be evaluated by the task. Only resource keys matching this pattern are accessible via the generated class.
  • genDir: The target directory for the generated files.
  • bundles: The file tree object defining the resource bundles to be evaluated by the task.

The generateI18N task scans the source set for any resource bundle matching the defined file pattern. For every found resource bundle it creates a Java class with same name as the resource bundle which can be used to access and format the resource strings. For example the resource bundle file:

I18N_CERT_EXPORT_TITLE = Export certificate
_STR_EXPORT_BUTTON = Export

results in the Java code

/*
 * I18N resource strings
 *
 * Generated on May 1, 2016 3:00:58 PM
 */
package de.carne.certmgr.jfx.certexport;

import java.text.MessageFormat;
import java.util.ResourceBundle;

/**
 * Package localization resources.
 */
public final class I18N {

	/**
	 * The BUNDLE represented by this class.
	 */
	public static final ResourceBundle BUNDLE = ResourceBundle.getBundle(I18N.class.getName());

	private static String format(String key, Object... arguments) {
		String pattern = BUNDLE.getString(key);

		return (arguments.length > 0 ? MessageFormat.format(pattern, arguments) : pattern);
	}

	/**
	 * Resource key {@code STR_CERT_EXPORT_TITLE}
	 * <p>
	 * Export certificate
	 * </p>
	 */
	public static final String STR_CERT_EXPORT_TITLE = "STR_CERT_EXPORT_TITLE";

	/**
	 * Resource string {@code STR_CERT_EXPORT_TITLE}
	 * <p>
	 * Export certificate
	 * </p>
	 *
	 * @param arguments Format arguments.
	 * @return The formated string.
	 */
	public static String formatSTR_CERT_EXPORT_TITLE(Object... arguments) {
		return format(STR_CERT_EXPORT_TITLE, arguments);
	}

}

Note that not for all keys access code have been created due to the task's keyFilter property.

Versions

Version
0.9.1