Build jar files which includes .class and .java files?

Hi,

I have a plain java project with a build.gradle file as follows:

apply plugin: 'java'

task sourcesJar(type: Jar) {
    from sourceSets.main.java.srcDirs
    classifier = 'sources'
}

artifacts {
    archives sourcesJar
}

I would like the output jar file to include both .class and .java files, but it only includes .class files. How can I include .java files?

Thank you

You should put something like
"
from sourceSets.main.java.output
from sourceSets.main.java.allSource
"

Hi, I’m getting the following errors when trying to include those:

task sourcesJar(type: Jar) {
    from sourceSets.main.java.output
    from sourceSets.main.java.allSource
    classifier = 'sources'
}

Error:(15, 0) No such property: output for class: org.gradle.api.internal.file.DefaultSourceDirectorySet

Error:(16, 0) No such property: allSource for class: org.gradle.api.internal.file.DefaultSourceDirectorySet

Sorry about that
I couldn’t check the doc.
This page says that it should be

from sourceSets.main.output
from sourceSets.main.allSource

Oh great that was it! Thank you so much for the help!