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.

4
  • 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? Commented Sep 24, 2014 at 1: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. Commented Sep 24, 2014 at 9:37
  • I'd consider removing the duplication by holding the version number in the build script and generating the class. Commented Sep 25, 2014 at 3: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? Commented Sep 26, 2014 at 8:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.