On 6/25/2023 2:10 PM, Tamás Cservenák wrote:
Multiple times come up on ML questions from users about "multi platform"
deploys/releases, where, AFAIK, some (usually) OS platform
dependant (usually native binary), comes to play.
…
- how are people doing it today?
For my projects I've spent years refining the GlobalMentor "Root POM" at
https://github.com/globalmentor/globalmentor-root/blob/main/pom.xml . If
your POM inherits from this POM, then you can define _a single property_
`exe.main.class` in your POM, and the build will automatically generate
the following (example assumes your project is named `my-cli`):
* A `my-cli-1.2.3-exe.jar` (which you can execute using `java -jar …`).
* A Linux self-executing script named `my-cli` (the executable JAR with
a Bash script starter embedded).
* A Windows executable `my-cli.exe`.
Furthermore if you specify `-P publish` for the profile when building,
it will also generate a `my-cli-1.2.3-bin.zip` file containing the
executables mentioned above, with executable bits set and everything,
for distribution.
Even this is not a complete solution; it still requires one to 1)
install Java, and 2) know what to do with an executable. (See the
[Install Datimprint CLI
instructions](https://www.jordial.com/software/datimprint/install), for
example.)
Still you can not imagine the pain I had to go through just to get this
much automation.
1. Maven doesn't really support expressions, so I had to create hacks on
top of kludges to get defining `exe.main.class` to work as a "toggle" to
turn other plugins on and off. I plan on writing a blog entry explaining
this one day, but for now just look for the multiple sequential regexes
for e.g. `<regex>_\$\{exe.main.class\}</regex>`. Yes, it is mind-bending.
2. In addition Maven's issue with undefined order of plugin execution
when defined in parent POMs was another huge roadblock (e.g.
[MNG-5799](https://issues.apache.org/jira/browse/MNG-5799) to pick one
random ticket out of many, requiring me to spread plugin executions
across multiple phases just to get some sort of deterministic order
(e.g. so I don't try to zip up the executables before they are created,
and I don't try to create the executables before the executable JAR is
created, etc.).
3. And speaking of assembly, I had to play even more tricks to get an
assembly defined in a parent POM, because the Maven Assembly Plugin
doesn't allow in-POM definitions of the assembly descriptor. (I can't
inherit a separate assembly descriptor defined in a parent POM, and I
need to have the assembly descriptor do property interpolation, etc.) I
actually use a hack in which the Antrun Plugin _generates_ the assembly
descriptor at just the right time (again, walking a tightrope just to
get this to all fall in place in the right sequence in the descendant POM).
The next step which I haven't yet taken is to have an installer for this
EXE/script/JAR, working across platforms. Supposedly JPackage addresses
this, but I soon realized that it's tied to the platform you're building
your project on, which is a non-starter—I don't want to set up build
separate pipelines for each separate targeted platform. I have thought
about seeing if I can integrate Docker into my Maven build to get around
this, but I haven't had time to research that further.
- what can Maven do to help more (if not fully support) this problem?
As explained with my harrowing hacks above, before we even get to
cross-platform targeted builds, there are a few fundamental Maven blind
spots that need to be addressed: 1) expression support, 2) deterministic
plugin execution ordering even when one plugin has multiple executions
defined in the same phase across parent and child POMs, and 3) in-POM
configuration of all plugins. (Kudos to the Versions Maven Plugin which
finally implemented this in
[#684](https://github.com/mojohaus/versions/issues/684).) I really
should not have had to take years and this many hacks and workaround
just to generate a few JARs and zip them up, based upon a property being
defined.
Otherwise it seems to me that more and more things are using Docker, and
Docker may be the only way to generate multi-platform targeted binaries
under some situations, so I guess increasing Docker interoperability may
be a general theme. (Maven may be there already—I confess I haven't had
a chance to do much with Docker from Maven other than generating images
using a plugin, and that's working with no problems so far, as long as
Docker is installed and running.)
Garret
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org