I want to publish a small library and I have a hard time to finde a solution to publish my sources alongside the dependency on jitpack.io .
The class files are available but nothing else.
This is my Gradle file:
plugins {
id 'java-library'
id 'maven-publish'
}
repositories {
jcenter()
mavenCentral()
}
//Problem part
task sourceJar(type: Jar, dependsOn: classes) {
classifier 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
//Problem part
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:27.0.1-jre'
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'org.reflections', name: 'reflections', version: '0.9.11'
}
Is there something wrong with my Gradle file or does anyone has a suggestion, where I can look up this issue?
The solution was a Publishing configuration.
Just replace the tasks and the artifacts with:
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
archiveClassifier.set("sources")
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set("javadoc")
from javadoc.destinationDir
}
publishing {
publications {
mavenAar(MavenPublication) {
from components.java
afterEvaluate {
artifact javadocJar
artifact sourcesJar
}
}
}
}
And now you can publish/release on Github via Jitpack.io and it will attach ressources and documentation.