0

I use the Gradle Java plugin and have the following source structure:

src/main/java/package1/
src/main/java/package2/

I want to create two source jars for each package directory, i.e.,

myproject-package1-sources-1.0.jar
myproject-package2-sources-1.0.jar

I can create the source jar for the whole project with:

task sourcesJar(type: Jar, dependsOn: classes) { 
  classifier = 'sources' 
  from sourceSets.main.allSource 
}

artifacts { 
   archives sourcesJar 
}

How can I create source jar for two projects with the appropriate names?

Edit: It could be that package1 and package2 are somewhere deeper like

src/main/java/a/b/e/package1/ 
src/main/java/x/y/z/package2/ 

It could also be possible that there are multiple packages1 and 2 like:

src/main/java/a/b/e/package1/ 
src/main/java/qwer/package1/ 
src/main/java/x/y/z/package2/ 

I want that that all files and subsequent files which are in folders named packages1 are includes it the first source jar and the same for the other package.

Michael
  • 32,527
  • 49
  • 210
  • 370

1 Answers1

0

This question is very similar to the one I just answered here: https://stackoverflow.com/a/29946192/950427.

Since you have "two" project that are in the "same" module or you have no modules what so ever, you need to be manually "specify" which directories you want.

You will need something like this:

task project1(type: Copy) {
    from('build/classes/main/package1/')

    into('another directory/')
    include('classes.jar')
}

task project2(type: Copy) {
    from('build/classes/main/package2/')

    into('another directory/')
    include('classes.jar')
}
Community
  • 1
  • 1
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185