eclipse / buildship

The Eclipse Plug-ins for Gradle project.
533 stars 170 forks source link

cannot use --args in run configuration - Gradle Task - Project Settings #1064

Open andreabisiach opened 3 years ago

andreabisiach commented 3 years ago

Expected Behavior

I have a Gradle build that applies the following plugins:

id 'java'
id 'application'
id 'idea'
id 'eclipse'

I need to pass parameters to the task 'run' while testing my application. From the command line i can run: /gradlew run --args="someargs" "someargs" is then passed to the public static void main(String[] args) of the class specified in:

application {
    mainClass = 'some.class'
}

I expect to be able to do the same from Eclips using Buildship.

Current Behavior

I tried adding --args="someargs" to the command: image But it raises the error: Task 'run --ars="someargs"' not found in root project

I have changed the command back to 'run' and added --args="someargs" as Program Argument image image Suddenly the task does not run at all and there is only this limited output in the Console. Nothing after "Gradle Tasks: run"

Gradle user home: /Users/andrea/.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 6.7.1
Java Home: /Applications/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.macosx.x86_64_15.0.1.v20201027-0507/jre
JVM Arguments: None
Program Arguments: --args="someargs" 
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: run

Gradle executions are empty image

Context

I need to simulate passing run parameters to my java application build with Gradle while coding in Eclipse

Steps to Reproduce

Your Environment

Gradle

------------------------------------------------------------
Gradle 6.8.2
------------------------------------------------------------

Build time:   2021-02-05 12:53:00 UTC
Revision:     b9bd4a5c6026ac52f690eaf2829ee26563cad426

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          15.0.1 (Oracle Corporation 15.0.1+9-18)
OS:           Mac OS X 10.15.7 x86_64

Eclipse

Eclipse IDE for Enterprise Java Developers (includes Incubating components)

Version: 2020-12 (4.18.0)
Build id: 20201210-1552

Buildship Eclipse Buildship Buildship, Eclipse Plug-ins for Gradle 3.1.5.v20210113-0904 org.eclipse.buildship

AndrewFerr commented 2 years ago

This is still an issue as of v3.1.6, but I stumbled on the solution: task options must be specified as entries in the "Gradle Tasks" list, on the Run Configuration's "Gradle Tasks" tab.

Note that space-separated arguments wrapped in quotes are passed as a single argument. To pass multiple arguments, they must be unquoted. In contrast, running Gradle from a shell may split quoted arguments. For example, using --args="a b" passes a single argument of "a b" in Buildship, but two arguments of "a" and "b" when invoking ./gradlew from bash. Meanwhile, --args=a b will set two arguments in Buildship, but will fail in bash unless all of "--args=a b" is quoted.

Also, using "Project Settings"->"Program/JVM Arguments" doesn't work unless their values are prefixed with -D or -P. It doesn't matter which prefix is added to which argument type. This suggests that when Buildship invokes Gradle, it doesn't add the proper command-line switches to those arguments.

nlisker commented 1 year ago

I hit a similar issue. I'm trying to run --write-verification-metadata sha256 help from Gradle and also getting "no task found" no matter where I put the flag and its arguments. @AndrewFerr If you have an idea on how to make this one work it would be helpful.

AndrewFerr commented 1 year ago

@nlisker What worked for me was setting the run configuration's Gradle Tasks to just help, and putting --write-verification-metadata & sha256 as two items under Project Settings > Advanced Options > Program Arguments.

nlisker commented 1 year ago

I tried AndrewFerr's solution. I don't get an error now, but the command doesn't run. The console shows

Working Directory: C:\Users\Nir\git\jfx
Gradle user home: C:\Users\Nir\.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 7.6
Java Home: C:\Program Files\Java\jdk-18
JVM Arguments: None
Program Arguments: --write-verification-metadata sha256
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: help

and nothing happens.