flatpak-builder
flatpak-builder copied to clipboard
possible to execute Maven build with flatpak-builder?
I would like to checkout a git repository, execute a Maven build and use the openjdk extension from Flathub to run the built application. Is this somehow possible? I've tried
{
"type": "shell",
"commands": [
"mvn clean package"
]
}
However, this only gives me /bin/sh: mvn: command not found
(which is not really surprising as mvn is not part of the freedesktop runtime/sdk).
Maven is not a part of any sdk... you will have to install as a dependancy first then clean it afterwards
@alexlarsson That reminds me shouldn't we have Maven, gradle and ANT as part of openjdk sdk extension. Without these build systems most of java projects won't be able to be built otherwise.
Once you built maven
you would use the simple build system:
{
"name": "foo",
"buildsystem": "simple",
"build-commands": [
"mvn build-or-something",
"mvn install-or-something"
]
}
@adityashah1212 any hints how I would do that (i.e. install Maven as dependency first)?
It would probably make sense to have these build tools in the sdk, i would love for some help adding them.
Maven can be built using ant, while ant depends on itself for building (I don't know if any other build systems are supported though). I think we will have to take a similar approach as we did openjdk here,
Ok. I think I will wait until it is available in the SDK (I don't know flatpak enough to implement the Maven build myself).
Ok, I opened a pull request to add maven, but it won't be able to pull dependencies on its own. not at the moment atleast. To support maven auto dependencies resolution and download, we either need to support maven in flatpak-builder or do what @alexlarsson did here for npm.
XAB: Running: strip --remove-section=.comment --remove-section=.note --strip-unneeded /home/builder/worker/build-aarch64/org.freedesktop.Sdk.Extension.openjdk9/.flatpak-builder/rofiles/rofiles-Uhi6Tf/files/share/maven/lib/jansi-native/freebsd32/libjansi.so
strip: Unable to recognise the format of the input file `/home/builder/worker/build-aarch64/org.freedesktop.Sdk.Extension.openjdk9/.flatpak-builder/rofiles/rofiles-Uhi6Tf/files/share/maven/lib/jansi-native/freebsd32/libjansi.so'
]2;flatpak-builder: Cleanup mavenError: module maven: Child process exited with code 1
I think we need to add a cleanup for the freebsd binaries.
How is the status of this issue? Is Maven build in now in the Sdk?
@H3sm4n Bumping issues like this is not helpful.
I just came across this issue, but I wanted to say that it's been possible to run mvn
in flatpak-builder
for at least a year now. In fact, I maintain two Flathub packages ([1], [2]) that make use of it.
You simply have to set a few environment variables so maven can work properly (actually, I think that just by adding /usr/lib/sdk/openjdk11/bin
to PATH
might be enough).
Of course, there's still no maven generator support in flatpak-builder-tools, so we can't generate all maven dependencies to a separate file. At least not easily. Which is required if you intend to get your app published on Flathub, since they run flatpak-builder
with --sandbox
, which denies mvn
internet access to download dependencies.
Albeit inconvenient, there is actually a way to generate these dependencies (example 1, example 2) yourself.
You just have to build your app with internet access first, so maven can download all dependencies. To to that, you'll have to add --share=network
under build-args
in your manifest file. Then, run flatpak-builder
with --build-only
and --keep-build-dirs
, and wait for your app to be compiled.
Now to generate a separate maven-dependencies.yaml
file, run these two commands (adjust the first command to use the build path of your app):
MAVEN_REPO="$PWD/.flatpak-builder/build/wallpaperdownloader/.m2/repository" # adjust here the path of your app
find $MAVEN_REPO \( -iname '*.jar' -o -iname '*.pom' \) -printf '%P\n' | sort -V | xargs -rI '{}' bash -c "echo -e \"- type: file\n dest: .m2/repository/\$(dirname {})\n url: https://repo.maven.apache.org/maven2/{}\n sha256: \$(sha256sum \"$MAVEN_REPO/{}\" | cut -c 1-64)\"" > maven-dependencies.yaml
There is a caveat, though: This will not work with dependencies that are not in repo.maven.apache.org
, which means you'll have to adjust them manually in maven-dependencies.yaml
.
This sounds somewhat inconvenient.