Is it possible to use an init.gradle script in IntelliJ Idea? - java

I'm using the Gradle wrapper in a project in Idead. I have an init.gradle file in a non-standard location and need to find a way to specify it in Idea. I thought this could be done via the Gradle VM options setting field and entered --init-script /path/to/init.gradle in it, but this throws an Unrecognized option --init-gradle /path/to/init.gralde error when trying to re-import the project.
Is there some other way to do this that I'm not aware of?

You can set Gradle commandline options/arguments from the "Run" configuration panel:
If you set this option on the "Templates>Gradle" panel it will apply to all Gradle tasks invocation ( note that you need to execute tasks with Right-click/Run from the Gradle tool window: double-click will not take the option into account..)
EDIT : another way is to add the commandline options directly in the "Run gradle task" window:

Related

Eclipse plugin dev: how to add default VM arguments by code?

While developing some plugins based on Eclipse, I need to add some default VM arguments when user right click-> "run as" -> "java application" or "spring boot app", is there any open api I can call or any extension point?
Just like the snapshot below, the argument "-Daaa=bbb" is added by default.
Any help is appreciated.
You need to write your own plugin and need to replicate/extend Java launch configuration
(of type Java application) from JDT and add -vm argument programmatically.
But there is one more easy way: Try LcDsl.
LcDsl provides a way of defining Eclipse launch configurations in a textual way. The file extension used is '.lc' It provides some obvious and some non-obvious advantages over the Eclipse launch configuration solution.
For more info look here and check demo videos. Also there was a discussion going on to include this plugin in JDT itself, see this bug entry.
A typical Java launch configuration looks like this:
java configuration LcJavaMain {
project com.wamas.test;
main-class com.wamas.test.JavaMain;
memory min=64m max=256m;
vm-argument '-Dmy.arg=value';
argument 'cmdArg';
}

How to configure Java Annotation Processor(s) in Eclipse?

I have successfully run annotation processor for CLASS level retention annotations via command prompt compiling using Java 8.
However, when I tried to configure the annotation processor in eclipse and tried to run it with "-proc:only" option, it didn't get effective.
I have included the Jar file containing the custom annotation processor class file into the Project Properties -> Annotation Processing -> Factory Path. I have also provided the -proc:only option in Project Properties -> Annotation Processing -> Processor Options, still the annotation processor isn't getting called when a class containing my annotation is executed.
Please help me identifying the required setting or mistake or additional step for running the annotation processor via eclipse.
I was finally able to enable my own annotation processor by adding my jar file.
Right click on the project and select Properties.
Open Java Compiler -> Annotation Processing. Check "Enable annotation processing".
Open Java Compiler -> Annotation Processing -> Factory Path. Check "Enable project specific settings". Add your JAR file to the list.
Clean and build the project.
And it finally worked.
It is very much straightforward provided that whatever APT plug in you are trying to use is correctly configured.
Follow the steps mentioned in above post and the reference image to visualize it. Image showing QueryDsl APT configuration for maven project.
While compiling via command prompt or terminal, you can see all the logs in same screen after the compilation command. In eclipse, these logs can be seen at
Window->show view->General->Error Log
If you want the IDE(Eclipse) to point out the warning, error or other diagnostic message exactly at the particular element in the code editor, we have to call the printMessage method of javax.annotation.processing.Messager with 3 arguments as shown below.
messager.printMessage(Kind.ERROR, "Error Message", element);

Regarding execution of .robot files for robot framework in IntelliJ

As it is specified everywhere for executing robot scripts you have to create maven project.I created the maven project and have added all the dependencies and plugin required for the execution. But when i create the maven project then by default a class ic created as AppTest.java in my src/test folder.Now when i add this .robot file in my test folder or main folder.It is not getting executed.Moreover i have a confusion how to execute these scripts.Please help me with this.Where should i place these file so that they could be executed.
I believe that at this time (7 months after your question) you've found a solution for the problem. If yes, I suggest you share it with the community.
Here's my solution, assuming that you're using Google Chrome:
Open the Edit Configurations window for your maven project, select the tab "Parameters", and in the field "Command Line" type "robotframework:run". It should look like this:
Then you select the tab "Runner" and add the property "webdriver.chrome.driver=/path-to-the-webdriver". It shoud look like this:
(note: uncheck the "Skip tests" check box. Mine is checked on the screenshot because I was testing other things.)
What's a little frustrating is that we can be misled by the error messages which say that you have to set the environment variable "webdriver.chrome.driver". In this case, we're tempted to add this variable to the field "Environment variables".
However, IntelliJ creates its own environment on run. That's why the field "Environment variables" doesn't work. When you add that property to the "Properties" box, the IntelliJ will convert it into a parameter in the run command, which will create the proper environment for the project.
Something like this:
/usr/lib/jvm/java-8-oracle/bin/java
-Dmaven.multiModuleProjectDirectory=/home/acampos/study/robotframework01
-Dmaven.home=/home/acampos/programs/idea-IU-172.4343.14/plugins/maven/lib/maven3
-Dclassworlds.conf=/home/acampos/programs/idea-IU-172.4343.14/plugins/maven/lib/maven3/bin/m2.conf
-javaagent:/home/acampos/programs/idea-IU-172.4343.14/lib/idea_rt.jar=36889:/home/acampos/programs/idea-IU-172.4343.14/bin
-Dfile.encoding=UTF-8
-classpath /home/acampos/programs/idea-IU-172.4343.14/plugins/maven/lib/maven3/boot/plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher
-Didea.version=2017.2.5
HERE!!!
-Dwebdriver.chrome.driver=/home/acampos/programs/chromedriver/chromedriver robotframework:run
So, when you run your maven project it will run the goal that's described on the Parameters tab, Command line field.
I hope it helps. And, again, if you've found another solution, please share with us.
Good luck!

How to make .properties read parameters from Jenkins

I use Jenkins to run regression periodically
I have java-maven project with 'ATC.properties' where I can choose browser, environment etc. by uncommenting appropriate one
#### browser ######
browser.name=firefox
#browser.name=chrome
#browser.name=ie
So I have to commit it, push and only after that job on Jenkins will run build with chosen parameters in 'ATC.properties' as well
How can I make my maven project read parameters from parametrised Jenkins build.
Can any one give me some example with browser ?
Do I have to use another one '.properties' file with described variables
like
browser.name=${browser.name} ...
in my project ?
Parameters defined in Jenkins will be expanded at run in Maven Build , Below process does not require additional property file :
Define jenkins choice parameter :
browser_name
Provide all your Browsers options as choices and select the required option at run time.
Now replace your pom.xml with ${browser_name} where you required the option of reading browser value instead of reading value from property file.
pass parameter at run time as below
mvn clean install -Dbrowser_name=%browser_name% [incase of windows]
mvn clean install -Dbrowser_name=$browser_name [incase of linux]

Defaults for Eclipse run configurations

I'm writing a Java library with a lot of jni code. Pretty much every test case needs to load my jni dll, and I have a lot of test cases. In order to run the test cases out of Eclipse's Junit launcher, I have to create a run/debug configuration and edit the VM arguments and environment variables.
I would like a way to set the VM arguments and environment variables to a default for the entire project and have new run configurations include the default entries. From what I can tell, Execution Environments maybe do something like this but I seem to need the PDE to get them to work(?)
Specifically, I want to enable assertions on my project by default and include the path to my native dll in the PATH environment variable. I can't use the "Default VM Arguments" setting in the JRE definition panel because my dll depends on a number of others and java.library.path isn't used for dependency resolution, PATH is. Is there a way to make Eclipse do what I want?
So, here's what I did.
First, my specific problem was that I have a lot of run configurations, I create new ones on the fly, and I needed certain system properties set for unit tests. Setting them under the 'args' tab of run configurations was undesirable for my workflow. Also, I wanted the same command-line args set for all of my tests. I also don't run my app from inside eclipse. It's a dev-environment only.
So my solution was to add it to the command-line of my JRE. Preferences -> Java -> Installed JREs. Clicking edit gives you a window where you can specify default VM args. I just set the system properties I need for testing there.
Hope this helps.
How long does it take to run all of your tests for the project?
If the answer is Not long then create a project-wide JUnit launcher. If occasionally you would need to do a run on a single test case ( in order to debug or something ), you can copy all your settings from the project's junit launcher. I think you can even clone your project launcher to run a specific test case.
Run->Run Configurations...
Create new JUnit launcher.
On 'Test' tab select Run all tests
in selected {...}
Connfigure JVM options, classpath,
environment etc. for this launcher
Optional, but highly recommended. On
Common tab -> Save as -> Shared
file, and check-in launcher with
your project
One more thing I would do is to define a system property in launcher VM arguments, check for this property in #Before function and throw exception if the property is not set. This way you will know that your test fails because it is not using the right launcher.
If I understand your question correctly, I think Alexander is on to the idea with cloning the project launcher. Eclipse lets you duplicate launch configurations with a single click - simply setup one configuration with the parameters you require and click the button in the top left to duplicate it whenever you create a new one.

Categories