craft_parts.plugins.gradle_plugin module

The gradle plugin.

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

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 keywords 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 keywords:

  • gradle-init-script: (list of strings) 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.

Parameters:
get_build_commands()[source]

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

Return type:

list[str]

get_build_packages()[source]

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

Return type:

set[str]

get_build_snaps()[source]

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.

properties_class

alias of GradlePluginProperties

validator_class

alias of GradlePluginEnvironmentValidator

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

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)[source]

Bases: PluginProperties

The part properties used by the gradle plugin.

  • gradle_init_script: (string) The path to init script to run before build script is executed.

  • gradle_parameters: (list of strings) Extra arguments to pass along to Gradle task execution.

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

Parameters:

data (Any)

gradle_init_script: str
gradle_parameters: list[str]
gradle_task: str
gradle_task_defined()[source]

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

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