Situation: I have a large project that developers may or may not pull down in its entiretiy.
I have one master build build.gradle that defines the dependencies of each package. What I’m trying to do is if the package has been checked out (i.e. exists) then make the dependency line be
compile project(’:common’)
if does not then I want the dependency to be
compile files(‘fullPathTo/common.jar’) If the developer has checked out the code I want it to build locally otherwise pull the jar from a controlled area (via NFS).
I don’t want to put the above conditional in many locations in my build.gradle file. My first thought is put it into a class and call it to add the dependency.
} I’ve tried many things but always seem to run into an error. The error for this code is:
No signature of method: localRemote.dependencies() is applicable for argument types: (localRemote$_determine_closure1) values: [localRemote$_determine_closure1@6edc77c4]
Hoping someone could point me in the right direction.
Your localRemote class gets compiled like a regular Java/Groovy class. So in your determine method, there isn’t a method in scope called “dependencies”. This is actually a method on Project that is backed by a DependencyHandler.
Great, some things you may want to consider: The best thing you could do would be to setup an artifact repository like Artifactory or Nexus versus using a NFS mount. You could then add a repository to your build script that would act like Maven Central or JCenter. Those tools are free, so the costs would be setting it up/maintaining it. If that’s not possible and you have control over the structure of the NFS mount, consider structuring it like a regular repository like Ivy or Maven.
Then your dependencies would be based on group:artifact:version instead of straight files. This would help you transition to using a real repository some day. Otherwise, your builds are going to be fragile (tied to NFS mount, no caching) and unrepeatable (you won’t know what you’re building against).
Thanks for the tip. Our managed area is very controlled, we tend to know what we are building against. I’m happy that I was able to show that gradle is much easier to read/maintain than ant.
I will push for structuring our SW to mimic a regular repository so that a transition to Maven is easier in the near future.