Using Cucumber with IntelliJ - intellij-idea

Does anyone knows why 'Cucumber Java' does not appear in "Edit Configurations -> Defaults -> ???? even though my pom file as downloaded the dependency i.e. cucumber-java (1.1.5)
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.38.0</version>
</dependency>
</dependencies>
Pom.xml file is used to install all the necessary plugins i.e. cucumber for java plugin

Make sure you have installed and enabled the Cucumber for Java plugin from the JetBrains plugin repository.
Look in the File -> Settings...
And you cannot install plugins into IDEA via Maven.

Just to add on top of the Answer by- Eugene.
While searching for Cucumber plugin, under File>Settings>plugins of Intellij you might not be able to see any Plugin available for cucumber and this is very weird issue for IntelliJ on windows.. troubled me for Hours..
But to solve it- we just have to click on 'Search in repositories' link as displayed on search panel. This will show all available stuff and you can select Cucumber for Java(or whatever).

Related

failed to resolve junit platform launcher 1.6.3 intellij

I am trying to run tests in Intellij which used to work earlier in spring boot 2.2.x. I recently upgraded to spring boot 2.3.9. When I try to run the test from Run Configurations, it doesn't run the test and throws the error:
'failed to resolve junit platform launcher 1.6.3 intellij'.
However if I run the test in cli, it works fine.
It turns out that, junit5-platform-launcher dependency needs to be added in order for Junit5 tests to run in IntelliJ.
https://youtrack.jetbrains.com/issue/IDEA-231927?_ga=2.5997872.2063517257.1613993298-1098513328.1597974168
https://junit.org/junit5/docs/current/user-guide/#running-tests-ide-intellij-idea
Add this dependency explicitly in pom.xml, and it will solve the issue.
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
I was facing same issue "failed to resolve junit platform launcher 1.8.1" intellij.
IntellJ version: 2021.3
I found answer here and it worked, no need to add any dependency to pom.
Go to settings >> HTTP Proxy >> choose auto-detect proxy settings
For IntelliJ Idea 2021.1, I fixed a similar problem with:
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
Maybe an even better fix is:
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.junit/junit-bom -->
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.7.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Found the above solution on Jetbrains issue tracker
If you have no direct internet connection but a repository manager like artifactory, idea tries to resolve junit-platform-launcher from there. Make sure u have a mirror to maven central repository (virtual repository) configured and the artifactory url to this mirror is accessible WITHOUT authentication (in the settings for the repo "Force Authentication" should be unchecked).
Check also the idea proxy settings and if needed, configure an exception for the artifactory domain.
Check your proxy settings in IntelliJ Idea settings. I turned ON the proxy and it solved the problem.
Here's the official way to do this
Maven Surefire and Maven Failsafe can run JUnit 4 based tests
alongside Jupiter tests as long as you configure test scoped
dependencies on JUnit 4 and the JUnit Vintage TestEngine
implementation similar to the following.
<!-- ... -->
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<!-- ... -->
<dependencies>
<!-- ... -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<!-- ... -->
</dependencies>
<!-- ... -->

IntelliJ cannot resolve Kotlin stdlib members within bundle

According to the Kotlin docs, there is an OSGi bundle for the Kotlin standard libraries. However, if I replace kotlin-stdlib with this bundle as recommended:
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-osgi-bundle</artifactId>
<version>${kotlin.version}</version>
<type>bundle</type>
</dependency>
IntelliJ is no longer able to find any classes or functions from the stdlib (i.e. println):
If I build and run the project (with maven-pax-plugin), everything works fine - it just seems to have broken IntelliJ's analysis capabilities.
How should I properly include Kotlin as an OSGi dependency?
I am using maven-bundle-plugin to build this bundle.
If you remove the type section, it should work:
<type>bundle</type>
The Kotlin OSGi bundle is not a Maven bundle artifact.
For Intellij IDEA 2018.2, works for me, using this way :
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-osgi-bundle</artifactId>
<version>${kotlin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>

IntelliJ doesn't autocomplete JUnit 5 Jupiter classes

I have Maven imports for JUnit 5 in an IntelliJ install, and I have invalidated the cache and restarted.
IntelliJ will refuse to autocomplete (CTRL-SPACE) any class nor any static method belonging to classes in the org.junit.jupiter.api. package, unless the class' fully qualified name is spelled out. Even when writing the package for which the class belongs, will not suggest the classes of that package.
IntelliJ version is 2017.2.1. Jupiter version is 5.0.0-RC2, platform is 1.0.0-RC2.
I am unsure how to move on from here. How come this package is the only one that seems to refuse basic completion?
<properties>
<junit.jupiter.version>5.0.0-RC2</junit.jupiter.version>
<junit.platform.version>1.0.0-RC2</junit.platform.version>
</properties>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- Only required to run tests in an IDE that bundles an older version -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<!-- Only required to run tests in an IDE that bundles an older version -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
Please check those classes are not in exclude list in File | Settings | Editor | General | Auto Import
You can try to downgrade JUnit 5 to M4 instead of RC2. IntelliJ 2017.2 is based on JUnit 5 M4, maybe that is causing the problem you are facing.

JUnit and WebDriver by IntelliJ IDEA

Im working in IntelliJ and need to add dependency's to Selenum WebDriver and Junit.
I already added the jars (as mentioned in all possible tutorial) to my Project lib.
I can also see them in the project view - Selenium-java-2.39.0.jar, Selenium-java-2.39.0.srcs.jar, Selenium-server-standalone-2.39.0.jar AND junit-4.11.jar
Nevertheless, my project can not recognized this items (for example
import org.openqa.selenium.;
import static org.junit.Assert.;
Any ideas?
I would recommend investing some time learning about some dependency management solutions. Here are my top two selections:
Maven
Ivy
If using maven, you'd have a pom.xml in your project and you'd have something like:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium_version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>${selenium_version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>${selenium_version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-safari-driver</artifactId>
<version>${selenium_version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-ie-driver</artifactId>
<version>${selenium_version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>${selenium_version}</version>
</dependency>
...
</dependencies>
Ivy is very similar, but i won't get into it. If you need a project to get you started, you can check out this project (download here) which is used by Major League Gaming for their selenium framework
I agree, you should invest in a dependency management solution, but if you are not forced to use maven, try gradle.
It is way lighter and flexible...
In that case, my dependencies are resume to 1 line:
compile "org.gebish:geb-spock:0.9.2", "org.seleniumhq.selenium:selenium-firefox-driver:2.39.0", "org.seleniumhq.selenium:selenium-support:2.39.0"
I agree, I could add a second line with a property for the selenium version.
Gradle is really well supported by intellij Idea.
enjoy

Can anyone give a good example of using org.apache.maven.cli.MavenCli programmatically?

I'm trying to create an intelliJ plugin that needs to execute maven targets on the current project. All the talk in the intertubes recommends using the MavenEmbedder. Good luck with that. The 2.0.4 version isn't well supported and there are no references for how to use it.
I gave it a whirl and ran into a wall where the embedder had not been initialized with all the fields it needs. Reflective private member injection? Awesome! Why would anyone need an obvious way to initialize an object?
It seems a few people are using a 2.1 version with some success. I have been unable to find that in a jar or even sources.
I went and checked out the 3.0 version of the embedder project: http://maven.apache.org/ref/3.0-beta-3/maven-embedder/ It does away with the MavenEmbedder object all together and seems to only support access through the main or doMain methods on MavenCli. Has anyone used these methods and can give some advice?
Yeah, the's not much in the way of documentation of MavenCli. The API is significatly simpler but i'd still like some examples. Here's one that works...
MavenCli cli = new MavenCli();
int result = cli.doMain(new String[]{"compile"},
"/home/aioffe/workspace/MiscMaven",
System.out, System.out);
System.out.println("result: " + result);
It takes a dir and runs the 'compile' phase...
Working maven configuration for maven 3.6.3
Code
MavenCli cli = new MavenCli();
System.setProperty("maven.multiModuleProjectDirectory", workingDirectory);
cli.doMain(new String[]{"compile"}, workingDirectory, System.out, System.err);
Dependencies
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.6.3</version>
</dependency>
<!-- https://issues.apache.org/jira/browse/MNG-5995 -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.6.3</version>
</dependency>
<!-- enable logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>
</dependencies>
The dependency matrix information for provided scopes and dynamically acquired components can be a bit confusing. It was for me, since it appeared to me that I got all the required items by direct or transitive dependency, but then remote resolution didn't work.
I wanted to jump to Maven 3.3.3 (latest as of 2015-05-25). I got it working without the sisu errors that presented when I tried to optimistically update to current versions of things specified here (and elsewhere). This is a project with a tag that worked with the example specified as of today using JDK8.
https://github.com/mykelalvis/test-maven-embedder/tree/20150525-working
Relevant deps (SLF4J is just so I can see the logs)
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>1.0.2.v20150114</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-wagon</artifactId>
<version>1.0.2.v20150114</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>2.9</version>
</dependency>
Running this is:
rm -r ~/.m2/repository/org/apache/maven/plugins/maven-clean-plugin/
mvn exec:java
Probably should have made it a unit test of some sort.
If someone has a superior solution for embedded Maven 3.3.3 (i.e. came up with a smaller or more range-oriented set of required dependencies), please post them.
to build on the comment from #StevePerkins, and using maven version 3.1.0,
I had to exclude the transitive dependency from aether-connector-wagon to wagon-provider-api to get it working.
pom.xml:
(...)
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
<version>0.9.0.M2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>2.5</version>
<scope>test</scope>
</dependency>
(...)
and here is a java example:
(...)
MavenCli cli = new MavenCli();
ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
ByteArrayOutputStream baosErr = new ByteArrayOutputStream();
PrintStream out = new PrintStream(baosOut, true);
PrintStream err = new PrintStream(baosErr, true);
cli.doMain( new String[] { "clean" }, new File("."), out, err );
String stdout = baosOut.toString("UTF-8");
String stderr = baosErr.toString("UTF-8");
(...)
full example here
There is a dependency matrix for each version of maven-embedder, e.g. for 3.2.5: http://maven.apache.org/ref/3.2.5/maven-embedder/dependencies.html
Based on that I had to use org.apache.maven:maven-embedder:jar:3.2.5, org.apache.maven:maven-aether-provider:jar:3.2.5, and org.apache.maven.wagon:wagon-provider-api:jar:2.8.
It also fixes dependency on very old Guava library, since this version uses 18.0.
Dependency list for Maven Embedded 3.6.3 version that works in my Spring Boot 2.3 project (JDK8 or JDK 11 runtime):
<!-- Maven Embedder -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>1.1.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-wagon</artifactId>
<version>1.1.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.usefultoys</groupId>
<artifactId>slf4j-toys</artifactId>
<version>1.6.3</version>
</dependency>
The Maven CLI command looks like to:
// Maven CLI to execute Maven Commands
MavenCli cli = new MavenCli();
int result = cli.doMain(args, workingDirectory,
org.usefultoys.slf4j.LoggerFactory.getInfoPrintStream(LOGGER),
org.usefultoys.slf4j.LoggerFactory.getErrorPrintStream(LOGGER));
HTH