How do I publish my .jar to a Maven repo (Project or application jar, not a 3rd party jar)

I have a project that compiles to a single .jar file that I want published to a Maven repo (Nexus). How do I do this?

This is the jar produced from building my application, not a 3rd party jar (that one would want to publish if it did not exist in a public repo anywhere).

I have read this document and it makes no sense.

First of all, why do I need this section?

  publications {

mavenJava(MavenPublication) {


} }

In each subsequent section of the above referenced document I do not know if the example is required code or optional; a working example would do wonders.

I know Maven really well but the Gradle syntex or sample code is not telling me a whole lot or I do not understand what is going on even when I have a document in front of me.

In the referenced Gradle sample, it shows:

  group = ‘org.gradle.sample’  version = ‘1.0.0’  

but in another document, I found this snippet:

  jar {

baseName = ‘MyProj’

version = ‘1.0.0’ }

Which one do I use? each separately on it’s on line, or nested within a jar { } enclosure…

What is the difference between “version” on its own line and within the "jal

I seem to be going in circles, when I google the subject I keep getting referred to

but the latest version of Gradle complains about that.

I am just looking for the minimum code to deploy the application I am building to a remote repo (where I have credentials to upload a .jar)

What exactly doesn’t make sense for you in the chapter? The gradle-all distribution contains a sample folder which contains sample build scripts to demo the maven-publish functionality. 

Question #1…3:

  1. What does the following snippet of code actually do?

  2. Why is it needed?

  3. is this snippet required or is it optional?

  publications {

mavenJava(MavenPublication) {


}  }  

Question #4

Is there a very minimal up to date example on what is needed in build.gradle for me to publish my built jar to a Maven/Nexus repo?

(need groupId, artifactId, version, project name, artifact type etc).

When I import a build.gradle file with this entry in the file, IntelliJ complains

  Build script error, unsupported Gradle DSL method found: ‘publications()’!

Possible causes could be:

Consult IDE log for more details (Help | Show Log)

Am I looking at an out of date example, and has this been hard deprecated? I still do not know what the section is attempting to communicate.