title: Building a self-executable JAR with Gradle and Kotlin
body: <p>I've written a simple Kotlin source file in order to get started, and a Gradle script file.
  But I can't figure out how to add the main function to the manifest, so that the JAR could be self-executable.</p>
  <p>Here is my build.gradle script :</p>
  <pre><code>buildscript {
      repositories {
          mavenCentral()
      }
      dependencies {
          classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.9.66'
      }
  }
  apply plugin: &quot;kotlin&quot;
  repositories {
      mavenCentral()
  }
  dependencies {
      compile 'org.jetbrains.kotlin:kotlin-stdlib:0.9.66'
  }
  
  jar {
      manifest {
          attributes 'Main-Class': 'com.loloof64.kotlin.exps.ExpsPackage'
      }
  }
  </code></pre>
  <p>Here is my <em>com.loloof64.kotlin.exps.Multideclarations.kt</em>:</p>
  <pre class="lang-kotlin prettyprint-override"><code>package com.loloof64.kotlin.exps
  
  class Person(val firstName: String, val lastName: String) {
      fun component1(): String {
          return firstName
      }
      fun component2(): String {
          return lastName
      }
  }
  
  fun main(args: Array &lt; String &gt; ) {
      val(first, last) = Person(&quot;Laurent&quot;, &quot;Bernabé&quot;)
      println(&quot;First name : $first - Last name : $last&quot;)
  }
  </code></pre>
  <p>When I launch the JAR from terminal (<code>java -jar MYJar.jar</code>) I get the following stack trace, saying that the Kotlin reflection library classes are missing, and indeed they have not been added to the JAR. It seems that I am missing the <em>kotlin-compiler</em> artifact classes from the final JAR, and also the <em>kotlin-stdlib</em> sources, but I don't know how to adapt the Gradle build.</p>
  <pre><code>$&gt; java -jar build/libs/kotlin_exps.jar 
  
  Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: kotlin/reflect/jvm/internal/InternalPackage
      at com.loloof64.kotlin.exps.ExpsPackage.&lt;clinit&gt;(MultiDeclarations.kt)
  Caused by: java.lang.ClassNotFoundException: kotlin.reflect.jvm.internal.InternalPackage
      at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 1 more
  </code></pre>
  <p>I am using Kotlin 0.9.66 and Gradle 2.1.</p>