Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » java.lang.NoSuchMethodError in okhttp3.RequestBody.create(java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)')
java.lang.NoSuchMethodError in okhttp3.RequestBody.create [message #1854168] Thu, 04 August 2022 08:54 Go to next message
Miloslav Frajdl is currently offline Miloslav FrajdlFriend
Messages: 41
Registered: June 2018
Member
Hi.

I need to create an application that performs cryptocurrency operations with Solana. I implemented the library https://github.com/Heaven-Land/solanaj.

In pom.xml I declared these dependencies:
	<!-- This is a library that works with Solana -->
	<dependency>
		<groupId>org.p2p</groupId>
		<artifactId>solanaj</artifactId>
		<version>1.0-SNAPSHOT</version>
	</dependency>
	<!-- These are the required dependencies -->
    <dependency>
      <groupId>org.bitcoinj</groupId>
      <artifactId>bitcoinj-core</artifactId>
      <version>0.16.1</version>
    </dependency>
    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>okhttp</artifactId>
      <version>4.9.0</version><!-- !!!!! A version conflict is reported here: "Overriding managed version 3.14.9 for okhttp" !!!!! -->
    </dependency>
    <dependency>
	    <groupId>com.squareup.moshi</groupId>
	    <artifactId>moshi</artifactId>
	    <version>1.9.2</version>
	  </dependency>
    <dependency>
	    <groupId>com.squareup.moshi</groupId>
	    <artifactId>moshi-adapters</artifactId>
	    <version>1.9.2</version>
	  </dependency>

In dependency for com.squareup.okhttp3/okhttp is reported warning: "Overriding managed version 3.14.9 for okhttp"

And I have this class:
import org.eclipse.scout.rt.platform.config.CONFIG;
import org.p2p.solanaj.core.PublicKey;
import org.p2p.solanaj.rpc.Cluster;
import org.p2p.solanaj.rpc.RpcApi;
import org.p2p.solanaj.rpc.RpcClient;
import org.p2p.solanaj.rpc.RpcException;

public class SolanaJUtils {
	public static Cluster getCluster() {
		String cluster = CONFIG.getPropertyValue(SolanaJCluster.class);
		if (cluster != null) cluster = cluster.toLowerCase();

		switch(cluster) {
		case "testnet":
			return Cluster.TESTNET;
			
		case "devnet":
			return Cluster.DEVNET;
			
		case "mainnet":
			return Cluster.MAINNET;
			
		default:
			return Cluster.DEVNET;
		}
	}
	
	public static Long getBalance(String address) {
		RpcClient client = new RpcClient(getCluster());
		try {
			RpcApi api = client.getApi();
			return api.getBalance(new PublicKey(address));	// <<<< !!!! ERROR IS THROWN HERE !!!!
		} catch (RpcException e) {
			e.printStackTrace();
			return null;
		}
	}
}


An error is thrown when calling the api.getBalance(new PublicKey(address)) method:
2022-08-04 09:58:51,255 ERROR [qtp596470015-56] org.eclipse.scout.rt.server.ServiceTunnelServlet.doPost(ServiceTunnelServlet.java:175) - Client=milos@127.0.0.1/127.0.0.1 - MDC[]
java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)'
	at org.p2p.solanaj.rpc.RpcClient.call(RpcClient.java:44)
	at org.p2p.solanaj.rpc.RpcApi.getBalance(RpcApi.java:59)
	at cz.a4b.tracetickets.server.solanaj.SolanaJUtils.getBalance(SolanaJUtils.java:87)


I tried:


But nothing helped.

When I link the same library in a normal Eclipse project (not Scout) including dependencies, it works.

Can someone please advise me what needs to be done?
Thank you.

---------------------------------------

EDIT 2022/08/04 17:54:
The problem is really that the required version of okhttp 4.9.0 is overridden by version 3.14.9 (see warning note above in dependencies). In version 4.9.0, the method is of the form: okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)
but in version 3.14.9 it is of the form: okhttp3.RequestBody okhttp3.RequestBody.create(okhttp3.MediaType, java.lang.String)

In the Manage Dependencies dialog it says: "Dependency okhttp-4.9.0 already declared with version 3.14.9 under org.eclipse.scout.rt:org.eclipse.scout.rt:11.0.42's dependencyManagement". This declaration is in C:\Users\milos\.m2\repository\org\eclipse\scout\rt\org.eclipse.scout.rt\11.0.42\org.eclipse.scout.rt-11.0.42.pom

Can anyone tell me how to tell Scout not to use managed version 3.14.9 but to use version 4.9.0? Thanks

[Updated on: Thu, 04 August 2022 15:54]

Report message to a moderator

Re: java.lang.NoSuchMethodError in okhttp3.RequestBody.create [message #1854223 is a reply to message #1854168] Mon, 08 August 2022 11:39 Go to previous message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 200
Registered: November 2010
Senior Member
Scout defines all dependency versions in the <dependencyManagement> section of the central pom.xml: https://github.com/eclipse-scout/scout.rt/blob/releases/11.0/org.eclipse.scout.rt/pom.xml

You should be able to override this in the <dependencyManagement> section of your own project pom.

This might be similar to this situation: https://stackoverflow.com/questions/34016904/maven-why-cant-i-override-the-version-of-a-dependencymanagement-imported-pom

Regards,
Beat
Previous Topic:Add JAR library to Scout project without Maven
Next Topic:Programmatically defined saved settings for table
Goto Forum:
  


Current Time: Wed Feb 21 21:12:56 GMT 2024

Powered by FUDForum. Page generated in 0.01917 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top