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.
-
1Can 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– Perryn Fowler2014-09-24 01:27:32 +00:00Commented 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.user1573546– user15735462014-09-24 09:37:08 +00:00Commented 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.Perryn Fowler– Perryn Fowler2014-09-25 03:53:36 +00:00Commented 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?user1573546– user15735462014-09-26 08:45:17 +00:00Commented Sep 26, 2014 at 8:45
Add a comment
|