Passing project parameter from command line needs workaround in Buildship


(Chryssa Charalambides) #1

I want to pass a parameter to the gradle script from the command line.

Our project has a dependency to a local jar that could be in different locations depending on the machine it runs. So I want to pass part of the path as a command line argument with -Ptranscad= so it’s machine specific. The jar can not be placed in a central location for all to access due to licensing issues.

I am able to do this with no problems from the command line but I am having problems with the Buildship plugin in eclipse.

this

dependencies {
compileOnly files(project.transcad+’/GISDK/Matrices/TranscadMatrix.jar’)
}

works perfect from the command line but produces the following error on Eclipse and the project in the gradle tasks view is marked with a red X indicating an error

Could not get unknown property ‘transcad’ for project ‘:ctramp21’ of type org.gradle.api.Project.

I have to do the following work around to get it to work on eclipse

def transcad_path = project.hasProperty(‘transcad’) ? project.transcad : ‘C:/TransCAD_6’

dependencies {
compileOnly files(transcad_path+’/GISDK/Matrices/TranscadMatrix.jar’)
}

This of course is an issue because we have a hardcoded path that could change from machine to machine. For example, when we do a gradle->refresh gradle project on a machine where the jar is on a different location we get compilation errors since it can’t find the jar to add it to the classpath.

Another problem is that Buildship runs some sort of Configuration check on the gradle projects when eclipse starts up or if you refresh the gradle tasks view, and there is nowhere to pass a command line parameter for that step. Unless there is and I have missed it. Does anyone know how to do this? This not when you run a specific task. I know how to set up the run configuration for specific tasks.


(James Justinic) #2

Is there a reason you don’t want to put the path to the transcad JAR in your GRADLE_USER_HOME/gradle.properties? It is typical to put properties that are machine or user specific in this location as it will be available to any build that needs it, but not part of the build.


(Chryssa Charalambides) #3

well the problem with that it is hardcoded again in the properties file and who ever runs it needs to update the path in that file


(James Justinic) #4

I’m not sure I understand your concern about “hardcoding” in the user properties file. That file exists just for this purpose (properties that may differ by user environment, not project). That file doesn’t leave the machine, so a user would set it once for the location of the JAR on that particular machine and never have to worry about it again. This would be equivalent to setting it somewhere in Buildship, but it would work for all cases, including command line without needing to pass the property every time.

I’m not suggesting that you put it in the properties file checked in with the project. Doing that would have the issues that you want to avoid.