Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Gradle Build From Eclipse without test

I have a gradle build file that uses the java plugin. If I want to invoke build from the command line and avoiding running unit tests I can just do this:

gradle build -x test

However, we'll be calling gradle tasks from Eclipse. Do I need to build a special task for this kind of build? How would I go about doing it?

like image 558
IcedDante Avatar asked Aug 05 '14 17:08

IcedDante


People also ask

How do I run Gradle without a test?

To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build. As a result, the test sources aren't compiled, and therefore, aren't executed.

Does Gradle build run tests?

By default, Gradle will run all tests that it detects, which it does by inspecting the compiled test classes. This detection uses different criteria depending on the test framework used. For JUnit, Gradle scans for both JUnit 3 and 4 test classes.

How do I run a build in Gradle?

Selecting Which Build to Execute When you run the gradle command, it looks for a build file in the current directory. You can use the –b option to select a particular build file along with absolute path. The following example selects a project hello from myproject. gradle file, which is located in the subdir/.


2 Answers

Under Eclipse > Menu bar "Windows" > Preferences > left hand side: Gradle> Arguments > Program Arguments > put -x test

and

Under Eclipse > Menu bar "Windows" > Preferences > left hand side: Gradle EnIDE> check box the box next to -x test (--exclude-task test) or use gradle assemble line.

See if that helps. Make sure GRADLE_HOME is set / known to Eclipse.

enter image description here

UPDATE:
THIS will stop running test task from any project (as it's global). If you just want to run gradle clean build -x test or similar (once in a while and only on some project), then do something like this:

  1. In GRADLE_HOME/init.d folder, create a global common file called shenzi.gradle
  2. In this common file, add the following:

    allprojects{
        apply plugin: 'java'
        apply plugin: 'groovy'
    
        // blah blah uncomment if you need.
        //apply plugin: 'pmd'
        //apply plugin: 'findbugs'
        //apply plugin: 'checkstyle'
        //apply plugin: 'jacoco'
    
        tasks.withType(Compile) {
            options.debug = true
            options.compilerArgs = ["-g"]
        }
    
        // ..
        // .. more code exists here for commented out lines as shown above, so ignore this in your version
        // .. 
    
        task myAliasNoTestBuild() << { 
            // see link below on how to create alias tasks
        }
    }
    

OR

try this solution: https://www.mail-archive.com/[email protected]/msg09173.html

OR

How to prevent gradle build from executing test task

like image 177
AKS Avatar answered Oct 12 '22 23:10

AKS


You can locally set this in eclipse

Right Click on build.gradle --> Run As --> Gradle build --> This will open a window.

Gradle task as :build
Program args as -x test

Refer below Image.. All set .. Run Now..

enter image description here

like image 27
rinuthomaz Avatar answered Oct 13 '22 00:10

rinuthomaz