Java : Gradle Project How to generate jar



Assume our projects package is ninja.sakib.gradlebuild and Initial Class (where main function belongs to) is MainBuilder, then
In build.gradle of your project add



jar {
    from {
        (configurations.runtime).collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    manifest { 
        attributes("Main-Class": "ninja.sakib.gradlebuild.MainBuilder")
    }
}

Note : If you are using Kotlin class then add Kt after class name. In our example it will be
ninja.sakib.gradlebuild.MainBuilderKt

If you don't want to add dependencies then remove from{} block.

Share this

Related Posts

Previous
Next Post »