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

**URL:** <https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900>\
**Category:** Uncategorized\
**Created:** [December 24, 2018, 10:07am UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900 "2018-12-24T10:07:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Riz](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Riz](https://discuss.kotlinlang.org/u/Riz)\
**Post date:** [December 24, 2018, 10:07am UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/1 "2018-12-24T10:07:25Z")

</div>

So, I’ve never used gradle before and after following the tutorial at [Migrating Builds From Apache Maven](https://guides.gradle.org/migrating-from-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?

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [December 26, 2018, 3:53pm UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/2 "2018-12-26T15:53:33Z")

</div>

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](https://www.excelsiorjet.com/).

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](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/8/89616f35f815a99962c78612a4196ee57b405621.png)

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:

- [http://kotlinlang.org/docs/reference/multiplatform.html](http://kotlinlang.org/docs/reference/multiplatform.html)
- [http://kotlinlang.org/docs/reference/building-mpp-with-gradle.html](http://kotlinlang.org/docs/reference/building-mpp-with-gradle.html)
- [http://kotlinlang.org/docs/tutorials/multiplatform-library.html](http://kotlinlang.org/docs/tutorials/multiplatform-library.html)
- [GitHub - orangy/multiplatform-lib: Sample multiplatform library in Kotlin with tests and publishing](https://github.com/orangy/multiplatform-lib)

---

<div class="post-metadata">

**Author:** ![Riz](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Riz](https://discuss.kotlinlang.org/u/Riz)\
**Post date:** [December 27, 2018, 9:53am UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/3 "2018-12-27T09:53:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [December 27, 2018, 10:03am UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/4 "2018-12-27T10:03:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [December 27, 2018, 2:07pm UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/5 "2018-12-27T14:07:38Z")

</div>

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](http://launch4j.sourceforge.net/).

---

<div class="post-metadata">

**Author:** ![Riz](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Riz](https://discuss.kotlinlang.org/u/Riz)\
**Post date:** [December 27, 2018, 6:10pm UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/6 "2018-12-27T18:10:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Riz](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Riz](https://discuss.kotlinlang.org/u/Riz)\
**Post date:** [December 27, 2018, 6:21pm UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/7 "2018-12-27T18:21:33Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![pkirill\_j](https://avatars.discourse-cdn.com/v4/letter/p/258eb7/32.png) [@pkirill\_j](https://discuss.kotlinlang.org/u/pkirill_j)\
**Post date:** [January 15, 2019, 10:28am UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/8 "2019-01-15T10:28:44Z")

</div>

> [@Riz](#):
>
> I was able to get Excelsior JET running and working!

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

---

<div class="post-metadata">

**Author:** ![Riz](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Riz](https://discuss.kotlinlang.org/u/Riz)\
**Post date:** [January 15, 2019, 11:39am UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/9 "2019-01-15T11:39:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pkirill\_j](https://avatars.discourse-cdn.com/v4/letter/p/258eb7/32.png) [@pkirill\_j](https://discuss.kotlinlang.org/u/pkirill_j)\
**Post date:** [January 15, 2019, 2:42pm UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/10 "2019-01-15T14:42:07Z")

</div>

> [@Riz](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Riz](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Riz](https://discuss.kotlinlang.org/u/Riz)\
**Post date:** [January 15, 2019, 3:04pm UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/11 "2019-01-15T15:04:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pkirill\_j](https://avatars.discourse-cdn.com/v4/letter/p/258eb7/32.png) [@pkirill\_j](https://discuss.kotlinlang.org/u/pkirill_j)\
**Post date:** [January 15, 2019, 3:36pm UTC](https://discuss.kotlinlang.org/t/how-to-convert-a-maven-project-to-a-gradle-project-for-use-with-kotlin-native/10900/12 "2019-01-15T15:36:42Z")

</div>

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

> **[jlink](https://docs.oracle.com/javase/9/tools/jlink.htm)**
>
> You can use the jlink tool to assemble and optimize a set of modules and their dependencies into a custom runtime image.

> **[The Incredible Shrinking Java Platform](https://www.azul.com/blog/the-incredible-shrinking-java-platform/)**
>
> JDK 11 will remove all support for applets and Java Web Start. Take advantage of the Java Platform Module System (JPMS) and use jlink to build applications.

> **[Using jlink to Build Java Runtimes for non-Modular Applications](https://medium.com/azulsystems/using-jlink-to-build-java-runtimes-for-non-modular-applications-9568c5e70ef4)**
>
> The most important new feature of JDK 9 was the Java Platform Module System (JPMS) that divided the monolithic rt.jar and tools.jar files…

> **[Jlink in Java 9 - DZone Java](https://dzone.com/articles/jlink-in-java-9)**
>
> Jlink is Java 9's new command line tool. See how you can use it to create your own lightweight, customized JRE for a module-based Java application.
