在没有测试的情况下从 Eclipse 运行 Gradle Build

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25145162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 21:50:44  来源:igfitidea点击:

Running Gradle Build From Eclipse without test

javaeclipsegradle

提问by IcedDante

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:

我有一个使用 java 插件的 gradle 构建文件。如果我想从命令行调用 build 并避免运行单元测试,我可以这样做:

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?

但是,我们将从 Eclipse 调用 gradle 任务。我需要为这种构建构建一个特殊的任务吗?我将如何去做?

采纳答案by AKS

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

Eclipse > Menu bar "Windows" > Preferences >左侧下方:Gradle> Arguments > Program Arguments >-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 assembleline.

Eclipse > Menu bar "Windows" > Preferences >左侧下方:Gradle EnIDE>选中-x test (--exclude-task test) or use gradle assemble行旁边的框。

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

看看是否有帮助。确保 GRADLE_HOME 已为 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 testor similar (once in a while and only on some project), then do something like this:

更新:
这将停止从任何项目运行测试任务(因为它是全局的)。如果你只是想运行gradle clean build -x test或类似的(偶尔并且只在某个项目上),那么做这样的事情:

  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
        }
    }
    
  1. 在 GRADLE_HOME/init.d 文件夹中,创建一个名为 shenzi.gradle
  2. 在这个公共文件中,添加以下内容:

    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

试试这个解决方案:https: //www.mail-archive.com/[email protected]/msg09173.html

OR

或者

How to prevent gradle build from executing test task

如何防止 gradle build 执行测试任务

回答by rinuthomaz

You can locally set this in eclipse

你可以在 eclipse 本地设置这个

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

右键单击build.gradle --> Run As --> Gradle build -->这将打开一个窗口。

Gradle task as :build
Program args as -x test

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

参考下图.. 全部设置.. 立即运行..

enter image description here

在此处输入图片说明