Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 526 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Build source jar with Gradle Kotlin DSL?

#1
[This question](

[To see links please register here]

) asks how to build a SourceJar with Gradle. How can I do the same with the Gradle Kotlin DSL?

The gradle code would be:

task sourcesJar(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
}
Reply

#2
The following will work:

val sourcesJar by creating(Jar::class) {
dependsOn(JavaPlugin.CLASSES_TASK_NAME)
classifier = "sources"
from(sourceSets["main"].allSource)
}

val javadocJar by creating(Jar::class) {
dependsOn(JavaPlugin.JAVADOC_TASK_NAME)
classifier = "javadoc"
from(tasks["javadoc"])
}

artifacts {
add("archives", sourcesJar)
add("archives", javadocJar)
}

A complete `build.gradle.kts` would look like this:

plugins {
kotlin("jvm") version "1.2.71"
}

repositories {
mavenCentral()
}

dependencies {
}

tasks {
val sourcesJar by creating(Jar::class) {
dependsOn(JavaPlugin.CLASSES_TASK_NAME)
classifier = "sources"
from(sourceSets["main"].allSource)
}

val javadocJar by creating(Jar::class) {
dependsOn(JavaPlugin.JAVADOC_TASK_NAME)
classifier = "javadoc"
from(tasks["javadoc"])
}

artifacts {
add("archives", sourcesJar)
add("archives", javadocJar)
}
}
Reply

#3
With Gradle 5.1 you can do something like this

tasks {
val sourcesJar by registering(Jar::class) {
classifier = "sources"
from(sourceSets.main.get().allSource)
dependsOn(classes)
}
val javadocJar by registering(Jar::class) {
classifier = "javadoc"
from(javadoc.get().destinationDir)
dependsOn(javadoc)
}
}
Reply

#4
With Gradle 5.3.1, this is a little nicer and avoids deprecated API:

tasks {
val sourcesJar by creating(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}

val javadocJar by creating(Jar::class) {
dependsOn.add(javadoc)
archiveClassifier.set("javadoc")
from(javadoc)
}

artifacts {
archives(sourcesJar)
archives(javadocJar)
archives(jar)
}
}

Task `assemble` will create all the artifacts.
Reply

#5
As of **Gradle 6.0** this is a much easier and cleaner. All you need to do is:

java {
withSourcesJar()
withJavadocJar()
}

Check out the documentation on the [java extension][1], and its functions, [withSourcesJar()][2] and [withJavadocJar()][3]


[1]:

[To see links please register here]

[2]:

[To see links please register here]

--
[3]:

[To see links please register here]

--
Reply

#6
All described methods fail with error on **Gradle 6.6**:
`SourceSet with name 'main' not found`

I've found a solution that works:
```
tasks {
val sourcesJar by creating(Jar::class) {
archiveClassifier.set("sources")
from(android.sourceSets.getByName("main").java.srcDirs)
}

artifacts {
archives(sourcesJar)
}
}
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through