Gradle dependency - class not found - java

I have a Gradle project in IntelliJ.
I added this dependency to Maven dependencies list
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
<version>4.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
When I try to compile my code using gradlew build I receive this compilation error:
gradlew build
:compileJava
....java:5: error: package org.imgscalr does not exist
import org.imgscalr.Scalr;
^
....java:52: error: cannot find symbol
BufferedImage thumbnail = Scalr.resize(image, 150);
^
symbol: variable Scalr
location: class PlaceController
2 errors
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
What is happening?
After adding the dependency inside maven file, IntelliJ automatically downloads the file and imports it where it is needed. By doing this, the error from the IDE, that says tahat Scalr could not be found, dissapears.

You should be covering this in your build.gradle file instead. Here's an example of how it would look.
repositories {
mavenCentral()
}
dependencies {
compile 'org.imgscalr:imgscalr-lib:4.2'
}
If you were looking to do a wholesale conversion from Maven to Gradle, you'd have to convert your POMs over first and iron out any bugs that may have resulted due to the conversion.

Related

Installing wasmerio using gradle fails

i've just tried using a webassambly in java.
I wanted to use wasmerio to achieve this but following the instructions at https://github.com/wasmerio/wasmer-java (The github page of wasmerio)
I ended up with an exception after running gradle build:
gradle build
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.wasmer:wasmer-jni-amd64-linux:0.2.0.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/org/wasmer/wasmer-jni-amd64-linux/0.2.0/wasmer-jni-amd64-linux-0.2.0.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
Required by:
project :
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 866ms
1 actionable task: 1 executed
My gradle build file look like the following:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation "org.wasmer:wasmer-jni-amd64-linux:0.2.0"
}
test {
useJUnitPlatform()
}
Any Ideas?
Thanks in advance

:app:dataBindingMergeDependencyArtifactsDebug' Error

What is causing the problem?
I am encountering such an error in my application sale. I couldn't find anything exactly as a solution.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:dataBindingMergeDependencyArtifactsDebug'.
> Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Could not resolve androidx.core:core-ktx:+.
Required by:
project :app
> Skipped due to earlier error
> Failed to list versions for androidx.core:core-ktx.
> Unable to load Maven meta-data from https://dl.bintray.com/kotlin/kotlin-eap/androidx/core/core-ktx/maven-metadata.xml.
> Could not get resource 'https://dl.bintray.com/kotlin/kotlin-eap/androidx/core/core-ktx/maven-metadata.xml'.
> Could not GET 'https://dl.bintray.com/kotlin/kotlin-eap/androidx/core/core-ktx/maven-metadata.xml'. Received status code 502 from server: Bad Gateway
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
As #Narendra_Nath said, it is because of the bintray dependencies and Jcenter shutting down.
you can refer to this article https://blog.gradle.org/jcenter-shutdown
the solution that worked for me is changing the repositories in the (Top-level build.gradle) to
buildscript {
repositories {
google()
mavenCentral()
maven {
url "https://repo.spring.io/release"
}
maven {
url "https://repository.jboss.org/maven2"
} }
You need to declare your dependency correctly "androidx.core:core-ktx:$core_version"
This is because bintray support is now no longer there.
Go to your project level build.gradle and comment out the
bintray dependencies in the allprojects and repositories section
Bintray Shutdown

My project, which uses a gradle dependency, stopped working when I restarted my computer

I am making a program that requires a Gradle dependency, and I am using eclipse. It was working yesterday, and I didn't change anything, but when I restarted my computer it stopped working. This is my first time using Gradle.
I tried refreshing Gradle and restarting eclipse, but it still doesn't see the dependency. I tried changing the distribution url of Gradle in the gradle-wrapper.properties file, and copying everything from one project to another but nothing has worked so far.
this is the content of my build.gradle file
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
apply plugin: "eclipse"
}
repositories {
maven {
url "https://dl.bintray.com/emilybjoerk/lisoft"
}
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// this is the dependency I am trying to get to work.
compile 'org.li-soft.gonector:gonector:1.0.0'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:27.0.1-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
This is the error message:
Could not run phased build action using Gradle distribution
'https://services.gradle.org/distributions/gradle-5.6.1-bin.zip'. A
problem occurred configuring root project 'MyGoEngine'. Could not open
cp_proj remapped class cache for ass53uh6ku2mc5yoyd4qs6g8f
(C:\Users\Nikolas.gradle\caches\5.6.1\scripts-remapped\build_159eps3wjadzhd5aqrvmhdzni\ass53uh6ku2mc5yoyd4qs6g8f\cp_proje7ca86eb00f9d6cbee2b842ef043afcb).
Could not open cp_proj generic class cache for build file
'C:\Users\Nikolas\eclipse-workspace\MyGoEngine\build.gradle'
(C:\Users\Nikolas.gradle\caches\5.6.1\scripts\ass53uh6ku2mc5yoyd4qs6g8f\cp_proj\cp_proje7ca86eb00f9d6cbee2b842ef043afcb).
BUG! exception in phase 'conversion' in source unit 'BuildScript'
org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to
org.codehaus.groovy.ast.expr.ArgumentListExpression
org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to
org.codehaus.groovy.ast.expr.ArgumentListExpression
I deleted the contents of C:\Users\Nikolas.gradle\caches, and ran again. This was the console error:
FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring root project 'MyGoEngine'.
Could not open cp_proj remapped class cache for j3obw14yy0cihl9fkn41unq7
(C:\Users\Nikolas.gradle\caches\5.6.1\scripts-remapped\build_159eps3wjadzhd5aqrvmhdzni\j3obw14yy0cihl9fkn41unq7\cp_proje7ca86eb00f9d6cbee2b842ef043afcb).
Could not open cp_proj generic class cache for build file 'C:\Users\Nikolas\eclipse-workspace\MyGoEngine\build.gradle'
(C:\Users\Nikolas.gradle\caches\5.6.1\scripts\j3obw14yy0cihl9fkn41unq7\cp_proj\cp_proje7ca86eb00f9d6cbee2b842ef043afcb).
BUG! exception in phase 'conversion' in source unit 'BuildScript' org.codehaus.groovy.ast.expr.TupleExpression cannot be
cast to org.codehaus.groovy.ast.expr.ArgumentListExpression
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 5s

Gradle compileJava Task keeps failing

alright i've been hiting my head against the wall for quite sometime now, and now i dont even know what to search for to find a solution, here are my files
build.gradle
//Applying the Gradle BND Plugin for Workspace Builds
//https://github.com/bndtools/bnd/blob/master/biz.aQute.bnd.gradle/README.md
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:${bnd_version}"
}
}
apply plugin: 'biz.aQute.bnd.workspace'
apply plugin: 'java'
// Repositorios, aguante Maven Central.
repositories {
mavenCentral()
/* Excluded, uso la dependecia de otro lado ahora.
flatDir {
dirs '/home/feddericokz/devTools/Equinox/Equinox-Oxygen-1a/plugins'
}
*/
}
// Dependencias
dependencies {
// https://mvnrepository.com/artifact/org.osgi/org.osgi.core
compile group: 'org.osgi', name: 'org.osgi.core', version: '6.0.0'
}
settings.gradle
/*
* This settings file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
* In a single project build this file can be empty or even removed.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user guide at https://docs.gradle.org/4.3.1/userguide/multi_project_builds.html
*/
/*
// To declare projects as part of a multi-project build use the 'include' method
include 'shared'
include 'api'
include 'services:webservice'
*/
rootProject.name = 'bndWorkspace'
include 'com.feddericokz.helloworld'
when trying to run gradle jar from the command line, i get an error as it the compiler cant find the osgi dependencies to compile the classes
Task :com.feddericokz.helloworld:compileJava FAILED
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:3: error: package org.osgi.framework does not exist
import org.osgi.framework.BundleActivator;
^
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:4: error: package org.osgi.framework does not exist
import org.osgi.framework.BundleContext;
^
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:6: error: cannot find symbol
public class HelloWorldActivator implements BundleActivator {
^
symbol: class BundleActivator
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:8: error: cannot find symbol
public void start(BundleContext bundleContext) throws Exception {
^
symbol: class BundleContext
location: class HelloWorldActivator
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:13: error: cannot find symbol
public void stop(BundleContext bundleContext) throws Exception {
^
symbol: class BundleContext
location: class HelloWorldActivator
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:7: error: method does not override or implement a method from a supertype
#Override
^
/home/feddericokz/testingDir/bndWorkspace/com.feddericokz.helloworld/src/com/feddericokz/helloworld/HelloWorldActivator.java:12: error: method does not override or implement a method from a supertype
#Override
^
7 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':com.feddericokz.helloworld:compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
2 actionable tasks: 1 executed, 1 up-to-date
What am i doing wrong?
EDIT: a typo
If you are using a Bnd workspace model build, then you must configure the build path through each project's bnd.bnd file using the -buildpath Bnd instruction. Then the Bnd gradle plugin will use that information to program the configurations for java compilation.
Your example shows setting a compile dependency for the root gradle project which is wrong since (1) you should be using -buildpath in the project's bnd.bnd file and (2) it is done in the root project which is not meaningful to any child projects like your com.feddericokz.helloworld project.
So change your build.gradle file to not apply the 'java' plugin to the root project and not set compile dependencies for the root project and change your Bnd workspace so that the workspace (cnf) has configured repositories to access the desired bundles, for example https://github.com/osgi/enroute.workspace/blob/4070ff6668a1ee79b9b01cfa4caab86869247e7b/cnf/ext/enroute.bnd#L22-L28, and then set each project's bnd.bnd file to have the desired bundles on the -buildpath.
It is unclear if bnd_version is defined in this line:
classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:${bnd_version}"
Consider adding a gradle.properties file with:
bnd_version=3.5.0
(or whatever version is apporpriate). As best as I can reproduce your situation, my example works for me with this.

Failed to apply plugin [class 'org.gradle.api.plugins.scala.ScalaBasePlugin']: Gradle v2.13

Trying to build my project with gradle 2.13.
Getting Error:
MUSGM186035-835:c gm$ gradle build
Version suffix : -6
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/gm/IdeaProjects/repo/a/b/c/build.gradle' line: 2
* What went wrong:
A problem occurred evaluating project ':b:c:QGInitiator'.
> Failed to apply plugin [class 'org.gradle.api.plugins.scala.ScalaBasePlugin']
> A dependency must not be empty
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or
--debug option to get more log output.
BUILD FAILED
Total time: 8.397 secs
My build.gradle file looks like,
apply plugin: 'java'
apply plugin:'scala'//Line with error
ourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile "org.scala-lang:scala-library:2.11.1"
}
This project is part of another project which has other gradle files. But I am not buling the parent project. Not sure what is happening with my dependency.
Stacktrace:
Caused by: org.gradle.api.InvalidUserDataException: A dependency must not be empty
at org.gradle.api.internal.tasks.DefaultTaskDependency.addValue(DefaultTaskDependency.java:122)
at org.gradle.api.internal.tasks.DefaultTaskDependency.add(DefaultTaskDependency.java:115)
at org.gradle.api.internal.AbstractTask$11.run(AbstractTask.java:323)
at org.gradle.api.internal.tasks.TaskMutator.mutate(TaskMutator.java:37)
at org.gradle.api.internal.AbstractTask.dependsOn(AbstractTask.java:321)
at org.gradle.plugins.ide.idea.IdeaPlugin$_configureForScalaPlugin_closure8.doCall(IdeaPlugin.groovy:229)
at org.gradle.plugins.ide.idea.IdeaPlugin$_configureForScalaPlugin_closure8.call(IdeaPlugin.groovy)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:67)
at org.gradle.internal.Actions$FilteredAction.execute(Actions.java:205)
at org.gradle.listener.ActionBroadcast.execute(ActionBroadcast.java:39)
at org.gradle.api.internal.DefaultDomainObjectCollection.doAdd(DefaultDomainObjectCollection.java:165)
at org.gradle.api.internal.DefaultDomainObjectCollection.add(DefaultDomainObjectCollection.java:159)
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:142)
Try applying the idea plugin to the root plugin. I'm not exactly sure what's going on, but that should solve the issue.

Categories