I have tried to implement the 'cucumber.api.cli.Main' but I get the following error: "No backends were found. Please make sure you have a backend module on your CLASSPATH." Does this mean I am missing a dependency? My Gradle and java code is below.
java code
package cucumber;
import cucumber.api.cli.Main;
import java.io.PrintStream;
public class CucumberRunEngine {
public static void main(String[] args) {
try {
Main.main(
new String[]{
"CLASSPATH:src.main.groovy.cucumber.features.addDeal",
//"-t", "#Daily",
"-g", "cucumber.stepDefinitions",
"-p", "pretty",
"-p", "html:target/HTMLReports/report.html",
"-p", "junit:target/JUNITReports/report.xml",
"-p", "json:target/JSONReports/report.json",
"-m"
}
);
} catch (Exception e) {
PrintStream printer =System.out;
printer.println(e);
for (int element=0;element<e.getStackTrace().length;element++) {
printer.println(e.getStackTrace()[element]);
}
}
}
}
Gradle code
plugins {
id 'groovy'
id 'java-library'
id 'application'
id "se.thinkcode.cucumber-runner" version "0.0.8"
}
dependencies {
//Standard
api "org.codehaus.groovy:groovy-all:${groovyVersion}"
api "com.reuters:corejavalib:${coreJavaLibVersion}"
api "com.oracle:ojdbc7:${ojdbc7Version}"
implementation "commons-io:commons-io:${commonsIoVersion}"
implementation "commons-lang:commons-lang:${commonLangVersion}"
//JUnit
implementation "junit:junit:${jUnitVersion}"
// implementation("org.junit.platform:junit-platform-suite")
compileOnly "org.testng:testng:${testNGVersion}"
//Cucumber
compileOnly "io.cucumber:cucumber-java:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-java8:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-junit:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-groovy:${cucumberGroovyVersion}"
compileOnly "io.cucumber:cucumber-gherkin:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-jvm-groovy:${cucumberGroovyVersion}"
compileOnly "io.cucumber:cucumber-junit-platform-engine:${cucumberVersion}"
implementation "io.cucumber:cucumber-core:${cucumberVersion}"
}
application{
mainClass="cucumber.CucumberRunEngine"
}
repositories {
}
Gradle.properties
# versions of dependencies used in this project defined here
groovyVersion=2.5.7
commonCliVersion=1.3.1
commonsIoVersion=2.6
commonLangVersion=2.6
#JUnit
jUnitVersion=4.8
testNGVersion=7.4.0
jUnitPlatformSuiteVersion=1.9.0
#Cucumber
cucumberVersion=7.4.0
cucumberGroovyVersion=6.10.4
ojdbc7Version=12.1.0.2
coreJavaLibVersion=3.5.21.9
Thank you for any help in advance :)
Your project setup is a bit peculiar. There are too many parts that simply don't belong. For example as a result of using compileOnly you're not including the code you need at runtime. And so Cucumber complains it can't find cucumber-java (a backend).
Now you may have already noticed this and scoped cucumber-core to implementation for this reason. But this suggests you're fixing one error at a time rather then building a fundamental understanding of the tools you use.
So it's worth reading how Gradle does dependency management for you:
https://docs.gradle.org/5.3.1/userguide/java_plugin.html#sec:java_plugin_and_dependency_management
A minimal example can be found in the skeleton project. It is not tailored to your needs, but it should be a good starting point.
https://github.com/cucumber/cucumber-java-skeleton
plugins {
java
}
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.0"))
testImplementation(platform("io.cucumber:cucumber-bom:7.6.0"))
testImplementation("io.cucumber:cucumber-java")
testImplementation("io.cucumber:cucumber-junit-platform-engine")
testImplementation("org.junit.platform:junit-platform-suite")
testImplementation("org.junit.jupiter:junit-jupiter")
}
repositories {
mavenLocal()
mavenCentral()
}
tasks.withType<Test> {
useJUnitPlatform()
// Work around. Gradle does not include enough information to disambiguate
// between different examples and scenarios.
systemProperty("cucumber.junit-platform.naming-strategy", "long")
}
Related
I am trying to build a simple maven library and I can't get it to build. I am using Gradle Groovy and Kotlin Multiplatform Library in IntelliJ IDEA.
I haven't even been able to begin coding since my dependencies wont load. I am very new to all this so bare with me.
This is my build.gradle
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.7.10'
}
group = 'me.me'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies{
implementation platform("io.cucumber:cucumber-bom:7.1.0")
implementation 'io.cucumber:cucumber-java'
implementation 'io.cucumber:cucumber-junit-platform-engine'
implementation 'io.cucumber:cucumber-junit'
implementation 'io.cucumber:cucumber-spring'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
}
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = '1.8'
}
withJava()
testRuns["test"].executionTask.configure {
useTestNG()
}
}
sourceSets {
commonMain {
}
commonTest {
dependencies {
implementation kotlin('test')
}
}
}
}
and this is the error I am getting
Build file '/Users/Me/Documents/GitHub/Project-Tools/build.gradle' line: 13
A problem occurred evaluating root project 'Project-Tools'.
> Could not find method implementation() for arguments
[DefaultExternalModuleDependency{group='io.cucumber', name='cucumber-bom', version='7.1.0', configuration='default'}]
on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I even tried commenting out each dependency one at a time so see if any work and none did
EDIT: Also I am on a Mac
I have a distributes projects with different sub-projects and I want to accomplish the following:
(root)
client
module A
module B
module C
model
I want to put
protoc {
artifact = 'com.google.protobuf:protoc:3.5.0'
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:1.7.0"
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
} }
dependencies {
compile "com.google.api.grpc:proto-google-common-protos:1.0.0"
compile "io.grpc:grpc-netty:1.7.0"
compile "io.grpc:grpc-protobuf:1.7.0"
compile "io.grpc:grpc-stub:1.7.0"
}
for module A, B and C.
For now I have the following in my root build.gradle
subprojects{
apply plugin: 'java'
sourceCompatibility = 1.8
group 'project'
version '0.0.1-SNAPSHOT'
jar {
manifest {
attributes 'Main-Class': "com.project.${project.name}.App"
}
doFirst {
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
}
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
}
}
So every sub-project use java plugin, and has the defines dependencies and jar task.
How can I only put the first block for some sub-projects ?
I tried using a variable like in Multi-project Builds - Gradle but I couldn't access it in subprojects block.
Thank you in advance. I'm really interested in using Gradle correctly and it's a bit hard to get into it outside of simple Android/Java projects. Feel free to include any documentations I should read :)
Edit:
Thank you. I wouldn't have posted here if I hadn't search before. Apparently I was missing the keyword "subset" who would have gave me the solution you linked.
A solution is described here: https://discuss.gradle.org/t/configure-only-subset-of-subprojects/5379/3
You can run configure() with a list of projects.
project.ext {
subprojectList = subprojects.findAll{
it.name == 'subprojectA' ||
it.name == 'subprojectB' ||
it.name == 'subprojectC'
}
}
configure(project.subprojectList) {
// insert your custom configuration code
}
or
configure([project(':a'), project(':b'), project(':c')]) {
// configuration
}
I have a common library that is published as a jar to maven local, which is then used by a set of very thin client applications. These applications basically feed their own configuration to the common library and initializes themselves as Spring applications.
This common library uses spring boot and a bunch of other dependencies. My question is, is it possible for me to not define spring boot as a dependency in the applications, and simply use the common library's spring version as a transitive dependency in all the applications?
I feel like this should be possible, but when I tried doing it, the springframework.org.boot classes are not being resolved (eg: #SpringBootApplication annotation).
These are my build.gradle files:
build.gradle from the common library
plugins {
id 'java-library'
id 'maven-publish'
}
group 'com.my.group'
version '1.0-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenLocal()
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'com.my.group'
artifactId = 'common-lib'
version = '0-alpha.1'
from components.java
}
}
}
configurations {
springBom
compileOnly.extendsFrom(springBom)
annotationProcessor.extendsFrom(springBom)
implementation.extendsFrom(springBom)
}
dependencies {
springBom enforcedPlatform('org.springframework.boot:spring-boot-dependencies:2.3.5.RELEASE')
api 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.cloud:spring-cloud-aws-messaging'
annotationProcessor 'org.springframework.boot:spring-boot-autoconfigure-processor'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
// a few other non-spring dependencies
}
build.gradle from a sample application
plugins {
id 'java'
}
group = 'com.my.group'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenLocal()
}
dependencies {
implementation group: 'com.my.group', name: 'common-lib', version: '0-alpha.1'
}
Example application initialization
package com.my.group.Core;
// none of the below are resolved
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
#SpringBootApplication(scanBasePackages = {"com.my.group"})
public class ConsumerApplication implements ApplicationRunner {
#Autowired
Core core;
public ConsumerApplication() {
}
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}
#Override
public void run(ApplicationArguments args) {
try {
core.processEvents();
} catch (ConfigurationException | InitializationException e) {
e.printStackTrace();
}
}
}
If I add in the following dependencies to my applications, everything works as expected.
springBom enforcedPlatform('org.springframework.boot:spring-boot-dependencies:2.3.5.RELEASE')
implementation 'org.springframework.boot:spring-boot-starter'
I found the issue. I have not included api in the configurations and as a result, the application could not resolve the version. Fixed by updating the build.gradle in my common library like so:
configurations {
springBom
compileOnly.extendsFrom(springBom)
annotationProcessor.extendsFrom(springBom)
implementation.extendsFrom(springBom)
api.extendsFrom(springBom)
}
I have a problem of conflicting dependencies.
The two jars are:
net.sf.jasperreports:jasperreports:6.4.1
com.connectifier.xero:client:0.13
Which both seem to be loading different versions of the same dependency:
org.bouncycastle.
I can't seem to get it to work no matter what I try.
Have been trying something like this:
configure(globalModule) {
dependencies {
compile('net.sf.jasperreports:jasperreports:6.4.1')
compile('com.lowagie:itext:2.1.7') {
exclude group: 'org.bouncycastle'
}
compile('com.connectifier.xero:client:0.13') {
exclude group: 'org.bouncycastle'
}
}
The error I keep getting is:
SecurityException: class "org.bouncycastle.asn1.pkcs.RSAPublicKey"'s signer information does not match signer information of other classes in the same package
The app will run fine if I do not import JasperReports, but I definitely need this.
I have resolved it! The normal method of exclude in gradle was not working and the workaround was as follows:
configure(globalModule) {
dependencies {
compile('net.sf.jasperreports:jasperreports:6.4.1')
compile('com.connectifier.xero:client:0.13')
compile('com.lowagie:itext:2.1.7')
}
configurations {
compile {
exclude group: 'org.bouncycastle'
exclude module: 'bcprov-jdk14'
}
}
task enhance(type: CubaEnhancing)
}
I've provided dependency scope configured like below. My problem is, the provided dependencies are not visible during runtime in tests. How can I configure this to keep the dependencies provided but available on the test classpath?
apply plugin: 'java'
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
}
}
dependencies {
provided 'com.google.guava:guava:18.0'
provided 'org.apache.commons:commons-lang3:3.3.2'
// Tests
testCompile 'junit:junit:4.11'
testCompile 'org.assertj:assertj-core:1.7.0'
// Additional test compile dependencies
testCompile 'joda-time:joda-time:2.2'
}
One solution is to add the dependency like the joda-time library with testCompile scope, but I don't want to duplicate any entries. I'm sure it can be achieved with proper configuration.
Two ways to do this. First, have the testRuntime configuration extend from provided.
configurations {
provided
testRuntime.extendsFrom(provided)
}
Second, you could add the provided configuration to the classpath of your test task.
test {
classpath += configurations.provided
}
Fixed with one additional line in configurations. Don't know if it's the best and a proper solution but works as intended.
configurations {
provided
testCompile.extendsFrom(provided)
}
my case
withType<Jar> {
enabled = true
isZip64 = true
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveFileName.set("$project.jar")
from(sourceSets.main.get().output)
dependsOn(configurations.compileClasspath)
from({
configurations.compileClasspath.get().filter {
it.name.endsWith("jar")
}.map { zipTree(it) }
}) {
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
}
}