How to convert a maven project to a gradle project for use with Kotlin native?

So, I’ve never used gradle before and after following the tutorial at Migrating Builds From Apache Maven I frankly still don’t know what I’m supposed to do.

Could anyone give me a very simple rundown of how I convert a maven project to gradle and then use kotlin native to create a native executable?

If you have a maven project written in Kotlin for JVM and want to produce native binaries, it would probably be easier to use tools like Excelsior JET.

If you still want to go Kotlin/Native way, beware that you’ll need to split your code base into the common part and platform specific parts. You place into the common part the code that depends on the Kotlin standard library and the existing multiplatform libraries. For the other parts of code that have dependencies on JDK and other JVM libraries, you either need to find their analogs among the existing multiplatform libraries, or reimplement these parts in Kotlin/Native either from scratch or with the help of native (e.g. C) libraries.

You can start by creating a new multiplatform gradle project with IntelliJ New Project wizard and then populating this newly created project with your code.
image

I recommend you to experiment with that multiplatform approach a little on some toy project, so you’d get a grasp of what that approach is and could make a more informed decision on which way to choose.

These materials regarding multiplatform projects might be helpful:

1 Like

Right now I’m not too interested in multiplatform support as what I’m generally making only has to run on windows machines, as such I was looking into ways of simply creating exe’s, I"ll have a look at Excelsior JET though thanks.

You can also look into GraalVM, which also provides native compilation and I think is much more convenient than Excelsior JET. But it does not have stable version for windows yet :frowning:.

Also if you need just an .exe launcher for your JVM application rather than fully precompiled native binaries, you can use a tool like launch4j.

Yes but using launch4j requires you to still distribute a (at least) 90mbs of java binaries not really solving anything.

Since I’m looking for something that’s like one single exe for windows.

Yeah I’ve looked into graal VM but as you said there’s no stable windows version yet, however, I was able to get Excelsior JET running and working!

The UI is a real blast from the 90’s though…

And how large it is ?
Did you manage to use jdk11 java linker in order to reduce resulting size?

The jar has a size of: 11 MB

The exe has a size of: 28 MB, however, it also has an “rt” folder which contains the extra files needed to make it run which is a whopping 184MB

I have not used the jdk 11 java linker as I’m not sure what it is / where it is.

Java linker is used to reduce number of classes (by removing unused java modules) and repackage your app with dependencies to a single module.

You can run it on you project and it should produce “minimal” jdk-11 based distribution of your program.

Previously you mentioned that you have to redistribute " 90mbs of java binaries" and then you said you get about 200+megs from Excelsior.

Since Excelsior and jdk-11 linker seems to be similar, it might be interesting to compare the results.

1 Like

Where / how do I use the Java linker? I can’t really find anything about it on the web.

Try googling “jlink”
Here is what I have found so far: