graalvm / native-build-tools

Native-image plugins for various build tools
https://graalvm.github.io/native-build-tools/
Other
349 stars 51 forks source link

Ability to easily generate a maven/gradle project that can be compiled to a native image #549

Open zakkak opened 7 months ago

zakkak commented 7 months ago

Is your feature request related to a problem? Please describe.

Often when trying to create a reproducer for a native image issue or show someone a Hello World example I end up copy pasting an older project and manually adjusting dependencies etc.

Looking at the "getting started" guides of native build tools there is an example but it feels kind of loaded. The application is not a simple "Hello World" but a fortune teller parsing a json file, the whole set-up requires the creation of a number of files by copy pasting code, etc.

Describe the solution you'd like

Ideally I would like a one/two liner(s) to get a simple project setup that can be compiled to native image.

For instance Quarkus offers the option to run quarkus create app org.acme:minimal and generates a project with the specified groupID and artifactID generating the maven pom files as well (it also supports generating gradle configs, and other options which are out of the scope of this issue).

Describe alternatives you've considered An alternative could be to mention in the "getting started" docs that one could glone https://github.com/graalvm/graalvm-demos/tree/master/java-hello-world-maven for a simple hello world, and have the fortune demo as a more advanced option.

cc @fniephaus

melix commented 7 months ago

I am not sure this has a lot of interest. The build plugins are not a project generator, they simply provide a plugin for integrating with Gradle or Maven. I do agree that the Maven setup is not straightforward, but that's Maven's verbosity's fault, nothing much we can do. We have samples in the repository that you can also copy and paste. As for generating projects, as you mentioned 3rd party frameworks have such generators which are actually much more likely to be used. Micronaut has start.micronaut.io which would give you a project in a couple seconds, that you are more likely to tweak. There's also https://graal.cloud/gcn/launcher/ . Spring also provides a starter.

For example, for my own demos, I simply end up writing:

mn create-app demo

And I'm done, I have exactly what you are asking for. I can then do ./gradlew nativeRun and I'm done. Bonus, I can also show this working in a Docker container by doing ./gradlew dockerBuildNative.

I am wondering in which circumstances you would generate a project without such a framework, beyond a demo. I'd be tempted to say that this is unlikely, so the effort in implementing such a feature is arguable, given that you can already generate projects with these. The counter argument is "I don't want to explain a framework to show a native image demo", but I'm not convinced that this is enough.

zakkak commented 7 months ago

The only use cases I can think of are the following:

  1. Generating CLI apps where I don't expect people to be willing to rely on a framework (jbang's native support seems to be a good option for such cases)
  2. Generating reproducers for https://github.com/oracle/graal/
  3. Generating demos in courses, workshops, presentations etc.

I agree that a minimal project one could git clone would probably suffice.

melix commented 7 months ago

Let's check our options.

  1. Generating CLI apps where I don't expect people to be willing to rely on a framework

Given that for CLI apps you are likely to implement CLI parsing, you will minimally use something like Picocli. With Micronaut you'd just change the mn command to mn create-cli-app clidemo and there you go, a native CLI app. I'm not familiar with JBang's native support, but it may be sufficient too.

  1. Generating reproducers for https://github.com/oracle/graal/

Right, this one may be useful to do without external frameworks. Copying one of the samples or cloning a demo repo might be good enough though.

  1. Generating demos in courses, workshops, presentations etc.

Well, same here. Either cloning a repo or using commands like mn create-app is IMO good enough. That's what I typically do in my own presentations (either using the mn CLI app, which I can also explain is actually built with native-image, or using the web UI which I also explain is deployed as a native image on multiple clouds). Of course the drawback of using mn or quarkus or the equivalent Spring thing in a presentation is that you're not there to talk about such frameworks. But, it's again a tradeoff here about us maintaining such a tool vs the simplicity of copy/pasting a sample.