Artifacts

Simple Jar

Jar task is provided by Java plugin. We can update its default configuration. For example, if we want to create a runnable jar, we need to provide main class, that will be inserted into manifest.

jar {
    manifest {
        attributes 'Main-Class': 'com.test.Main'
    }
}

Assemble task

When we have applied Java plugin, we can run gradle assemble in order to create jar files in build directory. We can update the defaults.

task sourcesJar(type: Jar) {
    baseName baseName
    classifier 'sources'
    from sourceSets.main.allSource
}
artifacts {
    archives sourcesJar // creates 'build/libs/myproject-sources.jar'
}

Create distribution

Apply plugin distribution and then we can create different distribution archives. Here we create main distribution, that contains all jars. Then we create docs distribution that contains all source files.

Publish artifacts

We can use maven-publish plugin to upload our artifacts into a repository.

Last updated

Was this helpful?