Skip to content

Commit

Permalink
feat(core22): maven plugin (#4657)
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
  • Loading branch information
cmatsuoka committed Mar 21, 2024
1 parent 06e15b3 commit 952ecb1
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"common/craft-parts/reference/step_execution_environment.rst",
"common/craft-parts/reference/step_output_directories.rst",
"common/craft-parts/reference/plugins/python_plugin.rst",
"common/craft-parts/reference/plugins/maven_plugin.rst",
# Extra non-craft-parts exclusions can be added after this comment
)
)
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Snapcraft.
:maxdepth: 1

/common/craft-parts/reference/plugins/dump_plugin
/common/craft-parts/reference/plugins/maven_plugin
plugins/maven_plugin
plugins/python_plugin
/common/craft-parts/reference/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/reference/plugins/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/reference/plugins/maven_plugin.rst
:start-after: .. _maven-details-end:
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-1.0.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

0 comments on commit 952ecb1

Please sign in to comment.