About apply plugin java

I want using Gradle ‘apply plugin : java’ to create a JAR file ,but I have my own src,and my own package name,not using default,how should i do ?

Hi finger,

Take a look at section 23.4.1 in the manual about configuring the project layout

sourceSets {

main {

java {

srcDir ‘src/java’


resources {

srcDir ‘src/resources’



If you have multiple srcDirs you can use
srcDirs = [ ‘/path/to/java/src’, ‘/a/second/path/to/more/java/src’ ] 
Regarding the name of the package, I assume you mean Jar file name, you can set this with the  archiveName  and  destinationDir properties of the Jar task to set your own.  See the section on Archive Naming and table in 16.8.1 for some examples.

Kind Regards

Thx for reply this question

My pleasure.

BTW, I should mention that the paths in srcDirs are relative to the project folder, so drop the first /. Eg srcDirs = [ ‘path/to/java/src’, ‘a/second/path/to/more/java/src’ ]

Enjoy using Gradle

I got it ,Thx