https://kotlinlang.org logo
#announcements
Title
# announcements
g

Gunslingor

09/16/2019, 12:13 PM
I've got a small little 24 lines of kotlin code that just queries java to get properties like version. Yet for some reason the jar that gets produced is 35MB in size. At the same time, the actual intelliJ project is only 9KB in size... this cannot be right, I use only native packages no imports, simple code, WTF is going on here?
Copy code
package org.ppp.installer

object JavaGetProperty {
    @JvmStatic
    fun main(args: Array<String>) {
        try {
            val property = args.getOrNull(0)
            var propertyVal: String

            if (property == "java_patch") {
                //Custom Properties
                val fullVersion = System.getProperty("java.version", "unknown")
                propertyVal = fullVersion.split("_")[1]
            } else {
                //Direct Unprocessed Properties
                propertyVal = if (property != null) System.getProperty(property, "unknown") else "unknown"
            }

            print(propertyVal.trim())
        } catch (e: Exception) {
            print("unknown")
        }
    }
}
t

tapchicoma

09/16/2019, 12:42 PM
check what is inside jar, it is in the end just zip archive
g

Gunslingor

09/16/2019, 12:52 PM
Thank you, I did think to check that but opened it in notepad instead of 7zip, lol, still learning thanks. So here is what I see inside there. Note that my boss told me to isolate this code in separate project and I did that and then built an artifact that was only 3KB in size (much more reasonable and inline with expectations)... however, it isn't working for some reason I presume because it can't find kotlin stds....
second isolated project
t

tapchicoma

09/16/2019, 1:08 PM
seems you are adding to your jar unnecessary dependencies
g

Gunslingor

09/16/2019, 1:08 PM
thank you.... that makes sense... much appreciated!!!
I revised all this in a new project so I can understand it. At the moment it seems to be spitting out all of kotlin?? is that necessary or do I have something configured wrong?
t

tapchicoma

09/16/2019, 6:27 PM
if "org" is your package - then looks ok
g

Gunslingor

09/16/2019, 6:27 PM
it is... just wondering why I need all of kotlin for such a tiny function.
It's 4MB...
for a paragraph of code, lol
t

tapchicoma

09/16/2019, 6:29 PM
kotlin
contains standard library. You could remove it by either dependence on stdlib or use tools like proguard
g

Gunslingor

09/16/2019, 6:30 PM
thank you... you know your stuff.
5 Views