I am trying to run the static core method of the java class from my build.gradle script asp art build process. I am using Android Studio 1.0.2 with Android / Gradle Plugin 'com.android.tools.build:gradle:1.0.0'
The java class whose main method I want to run at build time is in ... \ trunk- gradle \ myproject \ src \ main \ java \ de \ myapp \ gradle
package de.myapp.gradle; public class ConfigureCustomer { public static void main(String[] args){ String server = args[0]; String customer = args[1]; System.out.println(String.format("Configuring customer %s with server %s", customer, server)); } }
Before using ANT to call this java method as follows:
<java failonerror="yes" classname="de.myapp.gradle.ConfigureCustomer "> <classpath> <path location="${base.dir}/bin/classes/"/> </classpath> <arg line="${customer}"/> <arg line="${server }"/> </java>
But now I turn to Groovy, so here is the corresponding part of my project build.gradle file that is trying to execute the main method of the above class (the actual definition of the task is at the end before the dependencies):
apply plugin: 'com.android.application' android { project.ext.set("customer", "") project.ext.set("server", "") dexOptions { preDexLibraries = false } compileSdkVersion 19 buildToolsVersion "21.1.2" defaultConfig { //Default configuration } signingConfigs { release { //Configuration for release builds } } buildTypes { debug{ server = "test" } release { server = "release" } } productFlavors { customerA{ customer = "a" } customerB{ customer = "b" } customerC{ customer = "c" } } } task (configureCustomer, type: JavaExec) { println 'Running customer configuration...' main = 'de.myapp.gradle.ConfigureCustomer' args customer, server } dependencies { //Dependency settings }
So now when I run the following through the command line (windows):
graldew configureCustomer
The following error message appears:
Error: could not find or load the main class de.myapp.gradle.ConfigureCustomer
My questions are therefore the following:
- How do I fix the error message above? Should I move my java class to another folder? Maybe configure sth in the assembly?
- How can I make sure that the java task is executed after the classes have really been compiled?
- If I wanted to run the configureCustomer task as part of another task, can I just write the next line in the gradle task definition?
configureCustomer
I also tried adding the classpath:
task (configureCustomer, type: JavaExec) { println 'Running customer configuration...' main = 'de.myapp.gradle.ConfigureCustomer' classpath = sourceSets.main.runtimeClasspath args customer, server }
But all I got was a gradle build error message saying:
Could not find property "main" in SourceSet container
Therefore, apparently, "sourceSets.main.runtimeClasspath" does not exist in Android Studio Gradle. Maybe he is named differently. Although I also tried to set the classpath as follows:
classpath = '${projectDir.getAbsolutePath()}\\build\\intermediates\\classes\\' + customer + '\\release'
and I also tried this:
classpath = '${projectDir.getAbsolutePath()}\\build\\intermediates\\classes\\' + customer + '\\release\\de\\myapp\\gradle'
None of them worked, the error from above is saved:
Error: could not find or load the main class de.myapp.gradle.ConfigureCustomer