2

I am trying to get a gradle task to evaluate a static field in a class that was compiled in the same build file but I have not found a way to achieve that without doing stuff like JavaExec and have a Java main or a Groovy script output something to stdout (something like Running Groovy scripts from Gradle). Is there a way to evaluate a Java or Groovy expression in a task and set the classpath to the compile or runtime classpath of the project? The task would depend on compileJava, so I can be sure the code is compiled before the expression is evaluated.

Community
  • 1
  • 1
user1573546
  • 523
  • 5
  • 13
  • 1
    Can you elaborate on why you want to do this? Specifically, why does the class with the static field need to be in the main sourceset? – Perryn Fowler Sep 24 '14 at 01:27
  • This class holds an internal version number in a static member that is used to locate a native library. Since the build script also has to do things based on that version number I want to eliminate the duplication as a source of errors. Technically it does not seem such a big deal but so far I have only got it to work evaluating a groovy script in the main sourceSet which is misleading as this code is part of the build process and not of the product that is built. – user1573546 Sep 24 '14 at 09:37
  • I'd consider removing the duplication by holding the version number in the build script and generating the class. – Perryn Fowler Sep 25 '14 at 03:53
  • That's a possibility. If that class were not mine, (i.e. an external library) would there be a way, i.e. is there an answer to my original question, regardless of whether it is the way I should do it or not? – user1573546 Sep 26 '14 at 08:45

0 Answers0