I need to generate a jar file in IntelliJ where my test scenarios can be executed. I tried searching in google but all the information I found is deprecated and not working of fitting what I need. This is my project structure:
And this is my build.gradle file
plugins {
id 'java'
id 'application'
id "com.github.johnrengelman.shadow" version "7.1.2"
}
mainClassName = 'TestRunner'
version '0.1.0'
repositories {
mavenCentral()
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
dependencies {
// https://mvnrepository.com/artifact/io.cucumber/cucumber-java
implementation group: 'io.cucumber', name: 'cucumber-java', version: '7.2.3'
// https://mvnrepository.com/artifact/io.cucumber/cucumber-testng
implementation group: 'io.cucumber', name: 'cucumber-testng', version: '6.10.2'
}
distZip.shouldRunAfter(build)
jar {
// Keep jar clean:
exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.MF'
manifest {
attributes 'Main-Class': 'TestRunner',
'Class-Path': configurations.runtimeClasspath.files.collect { it.getName() }.join(' ')
}
// How-to add class path:
// https://stackoverflow.com/questions/22659463/add-classpath-in-manifest-using-gradle
// https://gist.github.com/simon04/6865179
}
def tags = (findProperty('tags') == null) ? 'not @Ignore' : findProperty('tags') + ' and not @Ignore'
task cucumber() {
dependsOn assemble, testClasses
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', '--glue', 'stepDefinitions', '--tags', "${tags}", 'src/test/resources/features']
}
}
}
And this is my TestRunner.java file
public class TestRunner {
public static void main(String[] args) throws Throwable {
io.cucumber.core.cli.Main.main(args);
}
}
I tried with many ways, trying to generate the FatJar but I don't get anything working. Now I'm trying to use it with shadowJar but I don't get it. I don't have very much expertise in this.
By now I can execute by CLI using the command, gradle cucumber -Ptags="@Simple" and I want to get something like this but with the jar file generated.
Can anyone help me with this?? Thanks!