I've created a small Apache Camel example, but it can't find the class org.apache.camel.impl.DefaultComponent. Here the full error log.
I've looked the class up on search.maven.org, which says it should be contained in org.apache.camel:camel-core. Adding it does not solve my problem.
What's wrong in this example?
This is the application
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.setWebApplicationType(WebApplicationType.NONE);
app.run(args);
}
}
and here the route.
#Component
public class ZmqRoute extends RouteBuilder {
#Override
public void configure() throws Exception {
//from("stream:in").to("stream:out");
String host = "zmq.devnet.iota.org";
from("zeromq:tcp://" + host + ":5556?socketType=SUBSCRIBE&topics=tx")
.to("stream:out")
.log("${body}");
}
}
Lastly, here the build.gradle.kts
plugins {
java
application
id("org.springframework.boot") version "2.1.2.RELEASE"
id("io.spring.dependency-management") version "1.0.6.RELEASE"
}
repositories {
jcenter()
}
application {
mainClassName = "org.example.camel.Application"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.addAll(arrayOf("-Xlint:all"))
options.encoding = "UTF-8"
}
dependencies {
val camelVersion = "3.0.0-M1"
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.apache.camel:camel-spring-boot-starter:$camelVersion")
implementation("org.apache.camel:camel-stream-starter:$camelVersion")
//implementation("org.apache.camel:camel-core:$camelVersion")
implementation("org.apache-extras.camel-extra:camel-zeromq:2.22.0") {
exclude(module = "zeromq-scala-binding_2.10")
}
implementation("org.zeromq:jeromq:0.5.0")
testImplementation("junit:junit:4.12")
}
So basically, after looking at Camel Core 3.0.0.M1, I discovered the .class file for
org.apache.camel.impl.DefaultComponent
doesn't exists anymore!
camel-core-3.0.0-M1.jar\org\apache\camel\impl
Honestly it seems like a bug to me, or incompatibility with core-zeromq.
The class has been moved to https://github.com/apache/camel/blob/master/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
so on a different package. This was reported also on the migration guide
https://github.com/apache/camel/blob/master/MIGRATION.md#migrating-custom-components
Related
I'm trying run with code with gradle and without it.
public class Example {
public static void main(String[] args) throws RuntimeException {
throw new RuntimeException();
}
}
With gradle it's not working.
[Exception when i run code with gradle][1]
[1]: https://i.stack.imgur.com/kJtyL.png
Without gradle it works.
I tried to run this code on java 8 - java 18 versions and used different versions of gradle.
My gradle file
plugins {
id 'java'
}
group 'org.example'
version '0.0.1'
repositories {
mavenCentral()
}
sourceCompatibility = JavaVersion.VERSION_18
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
test {
useJUnitPlatform()
}
How can I fix it?
Thank you!
I am writing selenium based browser tests , I would like to implement #Step annotation inside page object models which are in src/java folder.
When doing that I am not able to use / import #Step annotation ( i have gradle ktls plugin installed )
This is code which is part of page object model under src/java
#Step("Find flow based on file name : {fileName}")
public DataTable findByFileName(String fileName) {
selectedElement= dataTableElementList.stream()
.filter(dataTableElement -> fileName.equals(dataTableElement.getFile_name()))
.findFirst()
.orElse(null);
return this;
}
Overall idea is to annotate all steps which are taken in page object model methods and then use it to create step-by-step annotated report.
My kotlin build
buildscript {
repositories {
mavenLocal()
jcenter()
}
}
tasks.existing(Wrapper::class) {
gradleVersion = "4.10.2"
distributionType = Wrapper.DistributionType.ALL
}
description = "LM"
group = "ru.lm"
version = version
plugins {
java
id("io.qameta.allure") version "2.6.0"
id("io.freefair.lombok") version "5.3.0"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
val allureVersion = "2.9.0"
allure {
version = allureVersion
useTestNG {
version = allureVersion
}
downloadLink = "https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/$allureVersion/allure-commandline-$allureVersion.zip"
}
dependencies {
implementation("org.testng:testng:6.14.3")
implementation("com.fasterxml.jackson.core:jackson-annotations:2.12.3")
implementation("com.codeborne:selenide:6.2.1")
implementation("net.andreinc:mockneat:0.4.8")
implementation("com.konghq:unirest-java:4.0.0-RC2")
implementation("io.rest-assured:rest-assured:4.5.0")
implementation("org.hamcrest:hamcrest-all:1.3")
implementation("org.apache.logging.log4j:log4j-api:2.16.0")
implementation("org.apache.logging.log4j:log4j-core:2.16.0")
testImplementation("org.slf4j:slf4j-simple:2.0.0-alpha6")
}
tasks.named<Test>("test") {
useTestNG(closureOf<TestNGOptions> {
suites("src/test/resources/workflow.xml")
})
}
tasks.withType(JavaCompile::class) {
options.encoding = "UTF-8"
}
repositories {
mavenLocal()
jcenter()
}
I'm currently working on project with both Scala and Java. And we want to rewrite some Scala code on Java. So when I've been starting rewrite my code I've faced with this issue.
CountryResponse.java:5: illegal start of type declaration
It seem like Scala couldn't compile Java's records introduced in JDK 16. I've made some research and found only this discussion on GitHub. Could someone suggest any workaround to compile Java's records?
I did try increase Scala version from 2.12.2 to 2.13.6 but problem wasn't solved.
We use Java 16, Scala 2.12.2 and Gradle 7.0.1 and also scala and java plugins for Gradle.
Also here my gradle's settings for compile both sources.
compileScala {
sourceCompatibility("16")
targetCompatibility("16")
}
sourceSets {
main {
java {
srcDirs = []
}
scala {
srcDirs = ['src/main/scala', 'src/main/java']
}
}
}
edit: update link to discussion
I tested with following project containing both Scala and Java 16 sources. The Scala and Java source depends on each other.
If your both Java and Scala sources depend on each other, then you will need to put those sources under common folder. Lets say main/jvm.
You can place all your Java records under main/java. This will work as long as your records don't have dependency on Scala code. Otherwise you will have to break this into multiple modules and micromanage according to the dependency graph.
Gradle version is 7.1, and this project builds and then runs successfully (both ScalaMain and JavaMain).
build.gradle
plugins {
id 'java'
id 'scala'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
compileScala {
sourceCompatibility("16")
targetCompatibility("16")
}
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
scala {
srcDirs = ['src/main/jvm']
}
}
}
dependencies {
implementation 'org.scala-lang:scala-library:2.13.6'
}
main/java/TestJavaRecord.java
public record TestJavaRecord(int i) {}
main/jvm/TestScalaClass.scala
class TestScalaClass(val i: Int, val testJavaRecord: TestJavaRecord) {}
main/jvm/TestJavaClass.java
public class TestJavaClass {
public int i;
public TestScalaClass testScalaClass;
public TestJavaClass(int i, TestScalaClass testScalaClass) {
this.i = i;
this.testScalaClass = testScalaClass;
}
}
main/jvm/ScalaMain.scala
object ScalaMain extends App {
val testJavaRecord = new TestJavaRecord(5)
val testScalaClass = new TestScalaClass(5, testJavaRecord)
val testJavaClass = new TestJavaClass(5, testScalaClass)
println(testJavaRecord.i)
println(testScalaClass.testJavaRecord.i)
println(testJavaClass.testScalaClass.testJavaRecord.i)
}
main/jvm/JavaMain.java
public class JavaMain {
public static void main(String[] args) {
TestJavaRecord testJavaRecord = new TestJavaRecord(5);
TestScalaClass testScalaClass = new TestScalaClass(5, testJavaRecord);
TestJavaClass testJavaClass = new TestJavaClass(5, testScalaClass);
System.out.println(testJavaRecord.i());
System.out.println(testScalaClass.testJavaRecord().i());
System.out.println(testJavaClass.testScalaClass.testJavaRecord().i());
}
}
I am new to Gradle and i am using Gradle 6.1.
I am writing small application to understand the concepts of multi project Application and Java-Library plugin of Gradle.
My Question is :
How App.java is running perfectly fine without importing DefaultRandomGenerator class from SubProject-2
Why am i getting the error message "No candidates found for method call api" in build.grade file of Parent project (MultiProjectApp).
Below are my application code :
Parent Project (MultiProjectApp) files
settings.gradle
rootProject.name = 'MultiProjectApp'
include 'SubProject-1'
include 'SubProject-2'
build.gradle
allprojects {
apply plugin: 'java'
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
}
project(':SubProject-1') {
dependencies {
implementation project(':SubProject-2')
}
}
project(':SubProject-2') {
apply plugin: 'java-library'
dependencies {
api 'org.apache.commons:commons-math3:3.2'
implementation 'org.apache.logging.log4j:log4j-core:2.5'
testImplementation "junit:junit:4.12"
}
}
SubProject-2 files
build.gradle
Empty file
RandomGenerator.java
package org.examples;
public interface RandomGenerator {
String name();
int generate();
}
DefaultRandomGenerator.java
package org.examples;
import org.apache.commons.math3.random.RandomDataGenerator;
public class DefaultRandomGenerator implements RandomGenerator {
public String name() {
return "Main Random Number Generator";
}
public int generate() {
final RandomDataGenerator randomDataGenerator = new RandomDataGenerator();
return randomDataGenerator.nextInt(5, 10);
}
}
SubProject-1 files
build.gradle
Empty file
App.java
package org.examples;
import org.apache.commons.math3.random.RandomDataGenerator;
public class App {
public static void main(String[] args) {
RandomGenerator aRandomGenerator = new DefaultRandomGenerator();
System.out.println("The 1st random number is :" + aRandomGenerator.generate());
System.out.println("The 2nd random number is :" + generateMy());
}
public static int generateMy() {
final RandomDataGenerator aRandomDataGenerator = new RandomDataGenerator();
return aRandomDataGenerator.nextInt(5, 10);
}
}
How App.java is running perfectly fine without importing
DefaultRandomGenerator class from SubProject-2
It works because they are both in the same package (org.examples).
Note that this will not work if using the new module system introduced in Java 9. Because the two projects are considered "split", and you will need various hacks to make it work.
Why am I getting the error message "No candidates found for method
call api" in build.grade file of Parent project (MultiProjectApp).
This is an IDE problem, not a gradle problem. If you run, it should still work.
Example of runnig it in Vscode
Gradle has source Compatability and the targetCompatability variables that can be set. Eclipse has JDK compliance, generated class files comapatability, and source compatibility.
Is there any way to automagically set one from the other? Ideally, the Gradle stuff would be set from the Eclipse stuff.
edit: these things appear to be stored in: org.eclipse.jdt.core.prefs
edit2: they look like:
D:\ray\dev\conradapps\printg>cat .settings\org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
i can make it work as follows, but it's a hack :)
import java.io.IOException;
import java.nio.file.*;
import java.util.*;
plugins {
id 'java-library'
id 'application'
id 'distribution'
}
repositories {
jcenter()
}
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
dependencies {
testImplementation 'junit:junit:4.12'
}
String myMainClass='p.Main'
jar {
manifest {
attributes(
'Main-Class': myMainClass
)
}
}
application {
mainClassName = myMainClass
}
class Hack {
static String[] hack() throws IOException {
System.out.println("Working Directory = "+System.getProperty("user.dir"));
String dir="./.settings";
String name="org.eclipse.jdt.core.prefs";
File file=new File(dir,name);
String[] strings=new String[3];
for(int i=0;i<strings.length;i++)
strings[i]="";
if(file.exists()) System.out.println(file.toString()+" exists.");
else return strings;
List<String> lines=new ArrayList<>();
try {
if(usePath) {
Path path=FileSystems.getDefault().getPath(dir,name);
lines=java.nio.file.Files.readAllLines(path);
} else {
BufferedReader bufferedReader=new BufferedReader(new FileReader(file));
for(String line=bufferedReader.readLine();line!=null;line=bufferedReader.readLine())
lines.add(line);
bufferedReader.close();
}
int index;
for(String line:lines) {
if(line.startsWith("org.eclipse.jdt.core.compiler.compliance")) {
index=line.indexOf("=");
if(index>0) {
System.out.println("compliance: "+line.substring(index+1));
strings[0]=line.substring(index+1);
}
}
if(line.startsWith("org.eclipse.jdt.core.compiler.source=1.8")) {
index=line.indexOf("=");
if(index>0) {
System.out.println("source: "+line.substring(index+1));
strings[1]=line.substring(index+1);
}
}
if(line.startsWith("org.eclipse.jdt.core.compiler.codegen.targetPlatform")) {
index=line.indexOf("=");
if(index>0) {
System.out.println("target: "+line.substring(index+1));
strings[2]=line.substring(index+1);
}
}
}
} catch(Exception e) {
System.out.println("caught: "+e);
}
return strings;
}
public static void main(String[] args) throws IOException {
hack();
}
static boolean usePath;
}
println("java version is: ${JavaVersion.current()}")
String[] strings=Hack.hack();
if(strings[1]!="") {
println 'setting source'
sourceCompatibility = strings[1]
}
if(strings[2]!="") {
println 'setting target'
targetCompatibility = strings[2]
}
Yes. If you want Gradle to give your configuration to Eclipse, basically, as of Gradle 5.1.1, just add:
sourceCompatibility = '1.7'
targetCompatibility = '1.8'
to your build.gradle file. Note that until java 10 the enumeration was 1.8,1.9,1.10 but from Java 11 and future versions the enumeration is 11, 12, etc. Check the Gradle docs.
If you stumble upon this answer: For me, with Gradle 5.0, the java version works with or without quotes (either 1.8 or '1.8') and this is specified in the latest version of the javadocs. It also worked both when added inside and outside of compileJava{}. I tested this on a multiproject build.
I am not sure about the Eclipse to Gradle configuration transfer. Isn't it supposed to go the other way around though? Gradle is the central configuration tool that configures the build process and whatever IDE you are using (you, or your collaborator). Even if it is possible, the Gradle does manipulate the .classpath and other Eclipse files. So to be sure, if it was a crucial point, I would prefer to add the configuration to the Gradle and let that deal with Eclipse or any other IDE's files.