craft_parts.plugins.gradle_plugin module

The gradle plugin.

class craft_parts.plugins.gradle_plugin.GradlePlugin(*, properties, part_info)

Bases: JavaPlugin

A plugin to build parts that use Gradle.

The Gradle build system is commonly used to build Java projects. This plugin requires a build.gradle in the root of the source tree. This plugin uses the common plugin keys as well as those for “sources”. For more information check the ‘plugins’ topic for the former and the ‘sources’ topic for the latter.

Additionally, this plugin uses the following plugin-specific keys:

  • gradle-init-script: (string) Path to the Gradle init script to use during build task execution.

  • gradle-parameters: (list of strings) Flags to pass to the build using the gradle semantics for parameters.

  • gradle-task: (string) The task to run to build the project.

  • gradle-use-daemon: (boolean, default False) Whether to use the Gradle daemon during the build.

Parameters:
get_build_commands()

Return a list of commands to run during the build step.

Return type:

list[str]

get_build_environment()

Return a dictionary with the environment to use in the build step.

Return type:

dict[str, str]

get_build_packages()

Return a set of required packages to install in the build environment.

Return type:

set[str]

get_build_snaps()

Return a set of required snaps to install in the build environment.

Return type:

set[str]

property gradle_executable: str

Use gradlew by default if it exists, unless in self-contained mode.

properties_class

alias of GradlePluginProperties

classmethod supported_build_attributes()

Return the build attributes that this plugin supports.

Return type:

set[str]

validator_class

alias of GradlePluginEnvironmentValidator

class craft_parts.plugins.gradle_plugin.GradlePluginEnvironmentValidator(*, part_name, env, properties)

Bases: PluginEnvironmentValidator

Check the execution environment for the gradle plugin.

We can’t check for gradle executable here because if the project uses gradlew, we don’t necessarily need gradle to be installed on the system. We can’t check if the project uses gradlew since the project would not be pulled yet.

Parameters:
class craft_parts.plugins.gradle_plugin.GradlePluginProperties(**data)

Bases: PluginProperties

The part properties used by the gradle plugin.

Parameters:

data (Any)

gradle_init_script: str

The path to the initialization script to run before the build script is run.

The command run is gradle --init-script <gradle-init-script>.

gradle_parameters: list[str]

The extra arguments to pass to Gradle.

gradle_task: str

The Gradle task to run during build.

Defaults to build.

gradle_task_defined()

Gradle task must be defined.

This check ensures that the user does not override the default value “build” with an empty string.

Return type:

Self

gradle_use_daemon: bool

Whether to use the Gradle daemon during build.

Defaults to false.

model_config: ClassVar[ConfigDict] = {'alias_generator': <function PluginProperties.<lambda>>, 'extra': 'forbid', 'frozen': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

plugin: Literal['gradle']
source: str