> For the complete documentation index, see [llms.txt](https://ondrej-kvasnovsky-2.gitbook.io/gradle-handbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ondrej-kvasnovsky-2.gitbook.io/gradle-handbook/artifacts.md).

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

```
apply plugin: 'distribution'
distributions {
    main {
        baseName = baseName
        contents {
            from { libsDir }
        }
    }

    docs {
        baseName = "$baseName-docs"
        contents {
            from(libsDir) {
                include sourcesJar.archiveName
            }
        }
    }
}
```

## Publish artifacts

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

```
apply plugin: 'maven-publish'
publishing {
    publications {
        plugin(MavenPublication) {
            from components.java
            artifactId 'published-file'
            version '1.0'
            // groupId needs to be provided in order to publish to artifactory
            groupId 'org.gradle.sample'
            artifact sourcesJar
        }
    }
    // specify own maven local repository
    repositories {
        maven {
            name 'myLocal'
            url "file://$projectDir/repo"
            // gradle publishPluginPublicationToMyLocalRepository <= check the name, name of maven configuration is in the name of the task!
        }
        // to publish into remote and secured artifactory, use:
        maven {
            name 'JFrog'
            url "http://jfrog.com/your/repo"
            // gradle publishPluginPublicationToJFrogRepository
            credentials {
                username = ''
                password = ''
            }
        }
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ondrej-kvasnovsky-2.gitbook.io/gradle-handbook/artifacts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
