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

Add maven generator script #253

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

davidmhewitt
Copy link

Fixes #37

This is a script to generate a JSON file of sources that when included in a manifest, will download a set of maven dependencies into the flatpak-builder sandbox to enable the building of applications that would normally require downloading dependencies from Maven repositories.

I have used this to successfully build a proof of concept of a Kotlin/Native application: https://github.com/davidmhewitt/KotlinSample

You can see the generated JSON file here:
https://github.com/davidmhewitt/KotlinSample/blob/main/maven-modules.json

@TingPing
Copy link
Member

TingPing commented Jan 5, 2022

Looks reasonable, do you plan on helping actively maintain it?

@davidmhewitt
Copy link
Author

I would be happy to, yes.

maven/flatpak-maven-generator Outdated Show resolved Hide resolved
maven/flatpak-maven-generator Outdated Show resolved Hide resolved
maven/flatpak-maven-generator Outdated Show resolved Hide resolved
maven/flatpak-maven-generator Outdated Show resolved Hide resolved
maven/flatpak-maven-generator Outdated Show resolved Hide resolved
maven/flatpak-maven-generator Outdated Show resolved Hide resolved
@davidmhewitt
Copy link
Author

@gasinvein Thank you for the review! I've implemented your suggested changes and this is looking better now.

@TobTobXX
Copy link

I just tried this script with a libGDX project aaaaand.... you're gonna hate libgdx after this.

Take a quick look at this pom: https://repo1.maven.org/maven2/com/badlogicgames/gdx/gdx-backend-lwjgl3/1.10.0/gdx-backend-lwjgl3-1.10.0.pom

Two things that throw a wrench into this script: (btw, I'm just trying to figure out how maven works myself, so anything I say here is just how it looks to me)

  1. Apparently, depencencies can use variables in the style of <groupId>${project.groupId}</groupId> and <version>${lwjgl3.version}</version>. I'll have to research about what exactly that references, but maybe you already know it.
  2. There seems to be an additional classifier part of a dependency path (ie. not just groupId, artifactId, version, but also classifier). In this case, some examples include natives-desktop or natives-windows-x86. One dependency in the build.gradle is like this: com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop.

I'll try to fix it myself and report back, but you are probably more knowledgeable in the Java ecosystem.

Thanks for your work!

@davidmhewitt
Copy link
Author

@TobTobXX Thanks for trying it out!

I think I've implemented support for both of those things now if you'd like to try it out again and let me know how you get on 🙂

version = dep.find("POM:version", ns)

if(version is None):
continue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check out what's the matter with com.esotericsoftware:kryo? This check (although IMO really sensible) skips its dependency on reflectasm (gradle resolves the version to 1.11.3).

Copy link

@TobTobXX TobTobXX Feb 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I figured it out. kryo's parent (kryo-parent) somehow defines the version through a property in a <dependencyManagement> tag.

You know what, screw that dependency, I'll add it manually to the command.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there cases where silently continuing here is desired? If not, maybe log a warning and instruct the user to add it to the dependencies manually.

Oh, and thank you a lot for your work! You're awesome!

@TobTobXX
Copy link

TobTobXX commented Feb 15, 2022

After some more hours of testing and fiddling with my setup, I have now a script that works wonderfully for me!

I went with a different approach: I let gradle do the dependency resolution (ie. no stupid pom edge cases) into a fresh cache directory and then move the downloaded dependencies into a local maven repo. This also lets me derive the source urls from the directory structure (however, it only supports one repo atm, could fix if needed).

Here's the script that works (with some comments): flatpak-maven-generator.sh. It has to be run at the root of the gradle project and some variables at the top need to be adjusted.

@davidmhewitt Can you test it for your project? Then we could rewrite it in python (I'm bad at py and don't know how to do some stuff I did in the bash script), or we could get the bash script merged directly.

EDIT: Here's the updated script which supports multiple repos: flatpak-maven-generator.sh

@hfiguiere
Copy link
Collaborator

EDIT: Here's the updated script which supports multiple repos: flatpak-maven-generator.sh

Maybe submit a PR on top of this for these changes.

A maven generator would be great.

@hfiguiere
Copy link
Collaborator

I'm not sure I understand how this works.

Note: I'm totally clueless how Java build tools work, I have avoided it for 25 years.

% (cd ~/source/flathub/ar.com.tuxguitar.TuxGuitar/tuxguitar-1.5.6-src && /var/home/hub/source/flatpak-builder-tools/maven/flatpak-maven-generator.py -v org.herac.tuxguitar:tuxguitar-pom:1.5.6)
DEBUG:root:Looking up properties for tuxguitar-pom:1.5.6 at https://repo.maven.apache.org/maven2/org/herac/tuxguitar/tuxguitar-pom/1.5.6/tuxguitar-pom-1.5.6.pom
DEBUG:root:Looking for tuxguitar-pom:1.5.6 at https://repo.maven.apache.org/maven2/org/herac/tuxguitar/tuxguitar-pom/1.5.6/tuxguitar-pom-1.5.6.pom
WARNING:root:tuxguitar-pom:1.5.6 not found in any source
INFO:root:Output saved to maven-sources.json

whereas ~/source/flathub/ar.com.tuxguitar.TuxGuitar/tuxguitar-1.5.6-src is the unpacked tarball of the source (top level pom.xml)

maven-sources.json is empty.

@TobTobXX
Copy link

@hfiguiere Hi! Thank you for your interest.

I've reworked the script a couple of times since posting it here. Here's the current source: flatpak-gradle-generator.sh.

I would very much like to make it fit for this repo. I think it works, but testing it on different projects is extremely time-consuming and I've yet to test it to my satisfaction.

Also, could you post your problem as an issue on my fork? That'd make more sense, since polishing the script is a WIP still.

@hfiguiere
Copy link
Collaborator

I've reworked the script a couple of times since posting it here. Here's the current source: flatpak-gradle-generator.sh.

What I didn't pay attention to in my comment above is that yours is shell, while this PR is python.

Also, you mention gradle but here it is maven. Did I miss something?

@TobTobXX
Copy link

Yes, I am not the writer of this PR. The original PR author indeed wrote it in python and I just started to discuss improvements. At the time I started, I didn't really know the difference between maven and gradle. So this script is not a replacement of this PR, it's just what worked for me. You may have more success using the PR itself. If you have, you may help the author get it merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maven/Gradle support
5 participants