canonical / craft-parts

https://canonical-craft-parts.readthedocs-hosted.com
GNU Lesser General Public License v3.0
11 stars 36 forks source link

maven plugin should install maven build-package #812

Open vpa1977 opened 1 month ago

vpa1977 commented 1 month ago

Bug Description

maven plugin does not install maven build-package. In order to use maven plugin the image should have maven installed already which is inconvenient. Would it be possible to append

  build-packages:
      - maven
      - openjdk-21-jdk-headless

if the part does not contain 'build-packages'

To Reproduce

  1. create a rockcraft application with a maven part.
  2. rockcraft pack

part yaml

application:
    plugin: maven
    source: sample
    source-type: local

Relevant log output

2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.441 plugin validation command: 'mvn --version'
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.443 Environment validation failed for part 'application': 'mvn' not found and part 'application' does not depend on a part named 'maven-deps' that would satisfy the dependency.
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444 Traceback (most recent call last):
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_parts/plugins/validator.py", line 101, in validate_dependency
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444     output = self._execute(command).strip()
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_parts/plugins/validator.py", line 145, in _execute
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444     proc = subprocess.run(
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444   File "/snap/rockcraft/2374/usr/lib/python3.10/subprocess.py", line 526, in run
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444     raise CalledProcessError(retcode, process.args,
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444 subprocess.CalledProcessError: Command '['/bin/bash', '/tmp/tmpx0rd72pf']' returned non-zero exit status 127.
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444 The above exception was the direct cause of the following exception:
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444 Traceback (most recent call last):
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_application/services/lifecycle.py", line 256, in run
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444     with self._lcm.action_executor() as aex:
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_parts/executor/executor.py", line 304, in __enter__
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444     self._executor.prologue()
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_parts/executor/executor.py", line 91, in prologue
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444     self._verify_plugin_environment()
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.444   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_parts/executor/executor.py", line 290, in _verify_plugin_environment
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.445     validator.validate_environment(part_dependencies=part.dependencies)
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.445   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_parts/plugins/maven_plugin.py", line 64, in validate_environment
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.445     version = self.validate_dependency(
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.445   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_parts/plugins/validator.py", line 118, in validate_dependency
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.445     raise errors.PluginEnvironmentValidationError(
2024-08-16 11:32:31.728 :: 2024-08-16 11:32:31.445 craft_parts.errors.PluginEnvironmentValidationError: Environment validation failed for part 'application': 'mvn' not found and part 'application' does not depend on a part named 'maven-deps' that would satisfy the dependency.
2024-08-16 11:32:31.729 Executing on host: lxc --project rockcraft config device show local:rockcraft-maven-sample-chisel-on-amd64-for-amd64-61079577
2024-08-16 11:32:31.820 Executing on host: lxc --project rockcraft config device remove local:rockcraft-maven-sample-chisel-on-amd64-for-amd64-61079577 disk-/root/project
2024-08-16 11:32:31.954 Executing on host: lxc --project rockcraft stop local:rockcraft-maven-sample-chisel-on-amd64-for-amd64-61079577
2024-08-16 11:32:35.883 Failed to execute rockcraft in instance.
2024-08-16 11:32:35.885 Traceback (most recent call last):
2024-08-16 11:32:35.885   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_application/application.py", line 376, in run_managed
2024-08-16 11:32:35.885     instance.execute_run(  # pyright: ignore[reportUnknownMemberType,reportUnknownVariableType]
2024-08-16 11:32:35.885   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_providers/lxd/lxd_instance.py", line 293, in execute_run
2024-08-16 11:32:35.885     return self.lxc.exec(
2024-08-16 11:32:35.885   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_providers/lxd/lxc.py", line 387, in exec
2024-08-16 11:32:35.885     return runner(final_cmd, timeout=timeout, check=check, **kwargs)
2024-08-16 11:32:35.885   File "/snap/rockcraft/2374/usr/lib/python3.10/subprocess.py", line 526, in run
2024-08-16 11:32:35.885     raise CalledProcessError(retcode, process.args,
2024-08-16 11:32:35.885 subprocess.CalledProcessError: Command '['lxc', '--project', 'rockcraft', 'exec', 'local:rockcraft-maven-sample-chisel-on-amd64-for-amd64-61079577', '--cwd', '/root/project', '--', 'env', 'CRAFT_MANAGED_MODE=1', 'DEBIAN_FRONTEND=noninteractive', 'DEBCONF_NONINTERACTIVE_SEEN=true', 'DEBIAN_PRIORITY=critical', 'CRAFT_PLATFORM=amd64', 'CRAFT_VERBOSITY_LEVEL=BRIEF', 'rockcraft', 'pack']' returned non-zero exit status 1.
2024-08-16 11:32:35.885 
2024-08-16 11:32:35.885 The above exception was the direct cause of the following exception:
2024-08-16 11:32:35.885 Traceback (most recent call last):
2024-08-16 11:32:35.885   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_application/application.py", line 541, in run
2024-08-16 11:32:35.885     self.run_managed(platform, build_for)
2024-08-16 11:32:35.885   File "/snap/rockcraft/2374/lib/python3.10/site-packages/craft_application/application.py", line 383, in run_managed
2024-08-16 11:32:35.885     raise craft_providers.ProviderError(
2024-08-16 11:32:35.885 craft_providers.errors.ProviderError: Failed to execute rockcraft in instance.
2024-08-16 11:32:35.885 Full execution log: '/home/vladimirp/.local/state/rockcraft/log/rockcraft-20240816-113034.715917.log'
tigarmo commented 1 month ago

This is done on purpose; the idea is to give flexibility on the version of maven/jdk that you use for building the project. As you mentioned, the solution in the general case is to include those build-packages.

lengau commented 1 month ago

We should probably change this to behave like the rust plugin - If there's no maven-deps we install the system maven.

syncronize-issues-to-jira[bot] commented 1 month ago

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-3257.

This message was autogenerated

vpa1977 commented 1 month ago

We should probably change this to behave like the rust plugin - If there's no maven-deps we install the system maven.

Yes, it would be nice. Also maven depends on default-jre-headless, so we might want to have default-jdk-headless in build-packages too to deploy command line tools.

vpa1977 commented 4 weeks ago

Alternative is to make this change rockcraft-only