Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core22): maven plugin #4657

Merged
merged 18 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
# Excluded here because they are included explicitly in other documents;
# if we don't exclude them, they generate "duplicate label" errors.
"common/craft-parts/dump_plugin.rst",
"common/craft-parts/maven_plugin.rst",
"common/craft-parts/part_properties.rst",
"common/craft-parts/python_plugin.rst",
"common/craft-parts/rust_plugin.rst",
Expand Down
1 change: 1 addition & 0 deletions docs/reference/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ Snapcraft.
:maxdepth: 1

plugins/dump_plugin
plugins/maven_plugin
plugins/python_plugin
plugins/rust_plugin
37 changes: 37 additions & 0 deletions docs/reference/plugins/maven_plugin.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

.. include:: /common/craft-parts/maven_plugin.rst
:end-before: .. _maven-details-begin:

Dependencies
------------

The plugin expects Maven to be available on the system as the ``mvn``
executable, unless a part named ``maven-deps`` is defined. In this
case, the plugin will assume that this part will stage the ``mvn``
executable to be used in the build step.

Note that the Maven plugin does not make a Java runtime available in
the target environment. In Snapcraft, the developer must stage the
appropriate packages in order to be able to execute the application
(unless the Java runtime is provided by a
content snap).


Example
-------

This is an example of a Snapcraft part using the Maven plugin. Note
that the Maven and Java Runtime packages are listed as build packages,
and the Java Runtime is staged to be part of the final payload::

mkpass:
plugin: maven
source: .
build-packages:
- openjdk-11-jre-headless
- maven
stage-packages:
- openjdk-11-jre-headless

.. include:: /common/craft-parts/maven_plugin.rst
:start-after: .. _maven-details-end:
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ craft-application==1.2.1
craft-archives==1.1.3
craft-cli==2.5.1
craft-grammar==1.1.1
craft-parts==1.27.0
# craft-parts==1.27.0
craft-parts @ git+https://github.com/canonical/craft-parts@CRAFT-2584-Document-maven-plugin
craft-providers==1.23.0
craft-store==2.5.0
Deprecated==1.2.14
Expand Down
3 changes: 2 additions & 1 deletion requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ craft-application==1.2.1
craft-archives==1.1.3
craft-cli==2.5.1
craft-grammar==1.1.2
craft-parts==1.27.0
# craft-parts==1.27.0
craft-parts @ git+https://github.com/canonical/craft-parts@CRAFT-2584-Document-maven-plugin
cmatsuoka marked this conversation as resolved.
Show resolved Hide resolved
craft-providers==1.23.0
craft-store==2.6.0
cryptography==42.0.4
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ craft-application==1.2.1
craft-archives==1.1.3
craft-cli==2.5.1
craft-grammar==1.1.2
craft-parts==1.27.0
# craft-parts==1.27.0
craft-parts @ git+https://github.com/canonical/craft-parts@CRAFT-2584-Document-maven-plugin
craft-providers==1.23.0
craft-store==2.6.0
cryptography==42.0.4
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def recursive_data_files(directory, install_directory):
"craft-archives",
"craft-cli",
"craft-grammar",
"craft-parts",
# "craft-parts",
"craft-parts @ git+https://github.com/canonical/craft-parts@CRAFT-2584-Document-maven-plugin",
"craft-providers",
"craft-store",
"docutils<0.20", # Frozen until we can update sphinx dependencies.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>hello</artifactId>
<version>1.0</version>

<name>hello</name>
<description>A test project</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.example.hello.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: maven-hello
version: '1.0'
summary: A test project
description: |
A test project for the maven plugin. It says hello.

grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots
base: core22

lint:
ignore:
- library:
- usr/lib/jvm/java-*/lib/*.so

apps:
maven-hello:
command: bin/java -jar $SNAP/jar/hello-$CRAFT_PROJECT_VERSION.jar

parts:
hello:
plugin: maven
source: .
build-packages:
- openjdk-11-jre-headless
- maven
stage-packages:
- openjdk-11-jre-headless
prime:
- -usr/lib/jvm/java-11-openjdk-*/lib/security/blacklisted.certs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.hello;


public class Main {
public static void main(String[] args) {
System.out.println("hello world");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ environment:
SNAP/flutter: flutter-hello
SNAP/python: python-hello
SNAP/qmake: qmake-hello
SNAP/maven: maven-hello

prepare: |
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
Expand Down Expand Up @@ -87,6 +88,8 @@ execute: |
modified_file=lib/main.dart
elif [ -f src/hello/__init__.py ]; then
modified_file=src/hello/__init__.py
elif [ -f src/main/java/com/example/hello/Main.java ]; then
modified_file=src/main/java/com/example/hello/Main.java
else
FATAL "Cannot setup ${SNAP} for rebuilding"
fi
Expand Down