How to include java sources in a WAR file?

I have been reading this dicussion concerning the inclusion of the java source inside a JAR file.

How do we include the source inside a WAR file?

I guessed at:

war {
	from sourceSets.main.allSource
} 

but this didn’t seem to have any effect - the WAR didn’t seem to contain any source.

Anyone know?

Cheers,

I just tested this and it included the sources in the root of the war created in build/libs.

You could also try using the actual directory paths:

war  {
    from ('src/main') {
        into 'where/I/want/the/src'
    }
}

Try reproducing it in a small sample project without any other dependencies. Also if you could share more of your build.gradle script that might be useful.

Haha! Yes - my original guess was correct! It does work as expected and include the sources.
I think I was inspecting the wrong WAR file (Doh!)

Thanks for the additional tips though.