Amending my previous question: rather, what is the...
# gradle
s
Amending my previous question: rather, what is the best method to get all Java files within a project's sourceset? I'm trying to follow the Maven Publish plugin documentation, but having some difficulties since I'm using an older verison of gradle and the examples are in groovy.
Copy code
task sourcesJar(type: Jar) {
    from sourceSets.main.allJava
    classifier = 'sources'
}

task javadocJar(type: Jar) {
    from javadoc
    classifier = 'javadoc'
}
This is what the documentation says to do for Groovy
backporting it to 4.10.3 we get this:
Copy code
tasks.register<Jar>("sourcesJar") {
    from(sourceSets["main"].allJava)
    classifier = "sources"
}

tasks.register<Jar>("javadocJar") {
    from(tasks["javadoc"])
    classifier = "javadoc"
}
Note, I omitted the
project(":core")
here to be able to quickly test if it works on my machine (it does).
s
Thank you for the example, it does work! I just realise now that this is not actually what I need I'm pretty sure.. since my project uses Kotlin and not Java files.. 😩 All of my Jars are under the
lib
folder generated by the
jar
task.
Thank you for the example! This does work when I run without a project specified but gives me this error:
Extension with name 'sourceSets' does not exist. Currently registered extension names: [ext]
I'm not even sure I need to do it this way since my project is all Kotlin files and the Jars are stored in
build/libs
folder 😩
c
Here you go
Copy code
tasks {
	// other stuff you probably have in tasks {}

	register<Jar>("sourcesJar") {
		from(kotlin.sourceSets["main"].kotlin)
		classifier = "sources"
	}

	register<Jar>("javadocJar") {
		from(tasks["dokka"])
		classifier = "javadoc"
	}

	named<DokkaTask>("dokka") {
		outputFormat = "javadoc"
		outputDirectory = "$buildDir/javadoc"
	}
}
you will of course need dokka plugin:
Copy code
plugins {
    // other plugins
    id("org.jetbrains.dokka") version "0.9.17"
}
s
I will check this out as soon as my wifi returns so I can import Dokka. Thanks so much! I am woefully out of my depth with this buildscript
c
Yup, I was the same when I started tinkering, but at some point it just clicks and you start to understand logic behind it, then it's quite intuitive.
oh, by the way I'm assuming your script is *.gradle.kts, so my code is in kotlin-dsl, not groovy 🙂
s
Yes it is! Another issue with me looking at the Gradle docs for 4.10.2, all in Groovy 😞
c
yeah, 5.2.1 is a huge improvement, both in terms of the API and documentation.
s
@Czar the above code does work nicely. Thanks again!
👌 1
158 Views