Reputation: 23277
I'm trying to create a gradle file in order to publish my artifacts (.jar
, sources.jar
and javadoc.jar
).
Up to now, I've been able to write this gradle file:
plugins {
id 'java'
id 'eclipse'
id 'maven-publish'
id 'net.nemerosa.versioning' version '2.5.1'
}
targetCompatibility = 1.8
eclipse {
project {
name = 'OAuthz Library'
natures 'org.eclipse.buildship.core.gradleprojectnature'
}
classpath {
downloadSources = true
downloadJavadoc = true
defaultOutputDir = file('build-eclipse')
}
jdt {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'javax.servlet:javax.servlet-api:3.1.0'
compile 'org.codehaus.jettison:jettison:1.3.7'
compile 'org.apache.directory.api:api-all:1.0.0-M30'
compile 'com.whalin:Memcached-Java-Client:3.0.2'
compile group: 'org.mongodb', name: 'mongo-java-driver', version: '2.14.3'
compile 'commons-configuration:commons-configuration:1.10'
}
group = 'com.living'
version = versioning.info.display
manifest {
attributes 'Implementation-Title': 'OAuthz Library'
}
publishing {
publications {
mavenJava(MavenPublication) {
}
}
repositories {
maven {
credentials {
username 'user'
password 'passwd'
}
url "$url"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '3.1'
}
I've been able to publish my package on repository, nevertheless:
Any ideas?
Upvotes: 2
Views: 5200
Reputation: 28099
I use the nebula-publishing-plugin
plugins {
id 'nebula.javadoc-jar' version '4.4.4'
id 'nebula.source-jar' version '4.4.4'
}
If you don't want to use these plugins, you could use the code from the docs
tasks.create('sourceJar', Jar) {
dependsOn tasks.classes
from sourceSets.main.allSource
classifier 'sources'
extension 'jar'
group 'build'
}
publishing {
publications {
nebula(MavenPublication) { // if maven-publish is applied
artifact tasks.sourceJar
}
nebulaIvy(IvyPublication) { // if ivy-publish is applied
artifact tasks.sourceJar
}
}
}
Upvotes: 1
Reputation: 5174
1) You include a publishing block, but include no artifacts. That way only a pom is created. You need to include a from components.java
in your publishing definition:
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
...
2) You need to first create the artifacts:
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
Then include the artifacts into your publication:
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
}
}
...
Upvotes: 6