-->

How to do a Gradle setup for flat projects with no

2019-04-10 23:30发布

问题:

. . We are migrating to Rational Team Concert (RTC) and want to leverage its 'component' definitions. Components used in a stream result in a local scm workspace which is flat and its physical root is not in scm, like this:

|- workspace-name
   | component1
   | component2
   <empty>

Files in source code only exist in component folders, workspace-name is just a filesystem parent so unless I copied code into there at build time, it is empty of build files or code.

I found numerous good questions and answers on, e.g., flat project layouts, generic component layout, and an excellent primer on how Gradle works re: logical vs physical layouts. These still didn't quite address my confusion.

What I'm trying to do is this:

|- workspace-name
   | component1
   | component2
   | buildSrc

I have this in buildSrc/settings.gradle:

includeFlat '../component1/compa','../component2'

Right off the bat it gives me error that my custom task (defined in buildSrc\src\main\groovy\CustomTask.groovy) does not exist (could not find property 'CustomTask' on project ':component1/compa').

I believe that's because buildSrc should be in the projectroot directory itself (as implied by gradle docs) , e.g.:

|- workspace-name
   | component1
   | component2
     | buildSrc

Which leads me to think that maybe I need a dummy component which becomes both the logical parent as well as the buildSrc parent.

My question is, if I have no physical root, what's the "best" place to put my settings.gradle file? Each component will need code from the custom tasks to build so I'm also looking for the best place for that (if not in the dummy component). Thank you!

Andy

回答1:

I would try to stay away of dummy component, and:

  • either store a buildSrc folder in each component, with component-specific Gradle files
  • or store all buidSrc Gradle file in one component, and having a script able to copy/create what is needed in each component when a build is requested.


回答2:

There can only be one buildSrc per build, and you put it in the right place. However, buildSrc is its own build, and it doesn't make sense to make it include projects of the main build (as you apparently tried). Also the argument to includeFlat isn't a file path. Not quite sure what you are trying to achieve here.

As for the main build's settings.gradle, if you can't put it into the root directory, the other option is to put it into a directory named master. (This is a built-in convention and cannot be reconfigured.)



标签: gradle rtc