简体   繁体   中英

Main class for jar file missing for Gradle task

I have been trying to execute a jar file ssr.runner, jar using task with type JavaExec . But gradle is giving me the error that no main class specified . I am new to gradle so if any one could please elaborate in detail that would be great. Here is the task that I wrote:

task executeSqlScriptRunnerBeforeTenantCreation(type:JavaExec) {
    description "Execute ssr.runner to install certificates into the device"
    doLast {
        if(scriptRunnerVariables.get('SSR_INTERSECT_MOCK') == 'true') {

            println "Executing SQL Script Runner..."
            println "Adding certificates for mocked intersect service"

            if(scriptRunnerVariables.get('SSR_DB_TYPE') == 'SQL_SERVER') {
                classpath =  file("{$workingDir}\\ssr.runner.jar")
                main =  '-jar' 
                args '-dbtype', "${scriptRunnerVariables.get('SSR_DB_TYPE')}", '-dbhost', "${scriptRunnerVariables.get('SSR_DB_HOST')}", '-dbinstance', 
                "${scriptRunnerVariables.get('SSR_DB_INSTANCE')}", '-dbname', "${scriptRunnerVariables.get('SSR_DB_NAME')}", '-dbuser', "${scriptRunnerVariables.get('SSR_DB_USER')}",
                '-dbpass', "${scriptRunnerVariables.get('SSR_DB_PASS')}", '-sqlscriptpath', "${scriptRunnerVariables.get('SSR_INTERSECT_MOCK_DB_SCRIPT')}"  
            }    
        }
    }
}

First of all you're mixing two phases: execution and configuration . There's no need to add doLast for predefined tasks. See here . Then this is (probably) how the script should look like:

task executeSqlScriptRunnerBeforeTenantCreation(type:JavaExec) {
    description "Execute ssr.runner to install certificates into the device"

    if(scriptRunnerVariables.get('SSR_INTERSECT_MOCK') == 'true') {
        println "Configuring SQL Script Runner..."
        println "Adding certificates for mocked intersect service"

        if(scriptRunnerVariables.get('SSR_DB_TYPE') == 'SQL_SERVER') {
            main = '<FULLY QUALIFIED NAME OF CLASS YOU NEED TO RUN>' 
            classpath =  file("{$workingDir}\\ssr.runner.jar")            
            args '-dbtype', 
                 "${scriptRunnerVariables.get('SSR_DB_TYPE')}", 
                 '-dbhost', 
                 "${scriptRunnerVariables.get('SSR_DB_HOST')}", 
                 '-dbinstance', 
                 "${scriptRunnerVariables.get('SSR_DB_INSTANCE')}", 
                 '-dbname', 
                 "${scriptRunnerVariables.get('SSR_DB_NAME')}", 
                 '-dbuser', 
                 "${scriptRunnerVariables.get('SSR_DB_USER')}",
                 '-dbpass', 
                 "${scriptRunnerVariables.get('SSR_DB_PASS')}", 
                 '-sqlscriptpath', 
                 "${scriptRunnerVariables.get('SSR_INTERSECT_MOCK_DB_SCRIPT')}"  
            }
        }
    }
}

main was misconfigured there should be a fully qualified (with package) name of java class you need to run passed. Of course, what is configured via classpath , main , args and so on in configuration phase will be run in execution phase only if the two expressions in if block evaluate to true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM