0

My sources are in a folder structure like:

mygitroot/myproj/module1/src/main/groovy/com/mypak/module1 mygitroot/myproj/module2/src/main/groovy/com/mypak/module2 mygitroot/myproj/module3/src/main/groovy/com/mypak/module3

Gradle builds the jars in a folder structure like:

mygitroot/myproj/build/libs/module1.jar mygitroot/myproj/build/libs/module2.jar mygitroot/myproj/build/libs/module3.jar

I want it to output to the default dynamic folder structure, just rooted to a different "nongitroot" folder:

mybuildroot/myproj/build/libs/module1.jar mybuildroot/myproj/build/libs/module2.jar mybuildroot/myproj/build/libs/module3.jar

my task says this:

task sourcesJar(type: Jar) {
    group 'Build'
    description 'An archive of the source code'
    classifier 'sources'
    from sourceSets.main.allSource
}

Is there an elegant way to change just the root?

solvingJ
  • 1,321
  • 1
  • 19
  • 30
  • Possible duplicate of [Change Gradle's working directory when compiling a Groovy project](http://stackoverflow.com/questions/13915351/change-gradles-working-directory-when-compiling-a-groovy-project) – timtim17 Feb 03 '16 at 02:00
  • Set `buildDir` property – RaGe Feb 03 '16 at 02:29
  • Does not work as requested: – solvingJ Feb 03 '16 at 03:03
  • Does not work as requested, I'm guessing because "modules1-3" are subprojects of a parent project. I added buildDir="../my-build" under allprojects{ and it did create the folder and create "my-build/libs/parent.jar" and "my-build/temp". But it also created "my-build" in the root of my project, with "/classes", "/libs", and "/tmp" subdirs. Inside "/libs" were all 3 jars.... "module1.jar", "module2.jar", "module3.jar" . Very surprising. So, it seems I would need to specify each subprojects buildDir statically, in the build.gradle for each module (example: "myproj/src/module1" ). Correct? – solvingJ Feb 03 '16 at 03:17
  • Just set buildDir on the parent project, not the sub projects. – RaGe Feb 03 '16 at 04:47
  • But as I said, it doesn't do what I asked. – solvingJ Feb 03 '16 at 06:15
  • 1
    Why don't you just build them as normal, then have a task that moves them. Would that not be easier than trying to hack the build path for jar files? – tim_yates Feb 03 '16 at 08:29
  • Because nobody had suggested that until now :) Thanks Tim! Also, I didn't think it would be a hack, i thought it would just be a configurable thing, like most "path" variables. I'll move as you suggested, but selectively moving only subfolders that contain JAR to a new place, and maintaining the folder structure will be a non-trivial script. Also, this is my first project with gradle. – solvingJ Feb 03 '16 at 14:06

1 Answers1

0

Using answer from tim_yates - It turns out this is not a configurable option in Gradle, and thus is not natively possible. Going to create a move task instead.

solvingJ
  • 1,321
  • 1
  • 19
  • 30