flatpak-builder icon indicating copy to clipboard operation
flatpak-builder copied to clipboard

possible to execute Maven build with flatpak-builder?

Open plata opened this issue 7 years ago • 13 comments

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).

plata avatar Nov 04 '17 11:11 plata

Maven is not a part of any sdk... you will have to install as a dependancy first then clean it afterwards

adityashah1212 avatar Nov 04 '17 14:11 adityashah1212

@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.

adityashah1212 avatar Nov 04 '17 14:11 adityashah1212

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"
  ]
}

TingPing avatar Nov 04 '17 16:11 TingPing

@adityashah1212 any hints how I would do that (i.e. install Maven as dependency first)?

plata avatar Nov 05 '17 11:11 plata

It would probably make sense to have these build tools in the sdk, i would love for some help adding them.

alexlarsson avatar Nov 09 '17 09:11 alexlarsson

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,

adityashah1212 avatar Nov 09 '17 14:11 adityashah1212

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).

plata avatar Nov 09 '17 18:11 plata

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.

adityashah1212 avatar Dec 10 '17 01:12 adityashah1212

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.

alexlarsson avatar Dec 11 '17 09:12 alexlarsson

How is the status of this issue? Is Maven build in now in the Sdk?

H3sm4n avatar Mar 11 '20 08:03 H3sm4n

@H3sm4n Bumping issues like this is not helpful.

barthalion avatar Mar 14 '20 18:03 barthalion

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.

More details on how to build here.

guihkx avatar Feb 18 '21 17:02 guihkx

This sounds somewhat inconvenient.

plata avatar Feb 20 '21 16:02 plata