Hi I'm new to gradle and java and IJ idea. I am trying to build some java project using gradle. When I run command:
C:\Users\xxx\IdeaProjects\example2>gradle build
The build fails.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestJava'.
> Could not resolve all files for configuration ':testCompileClasspath'.
> Could not resolve org.testng:testng:6.14.3.
Required by:
project :
> Could not resolve org.testng:testng:6.14.3.
> Could not get resource 'https://repo.maven.apache.org/maven2/org/testng/testng/6.14.3/testng-6.14.3.pom'.
> Could not GET 'https://repo.maven.apache.org/maven2/org/testng/testng/6.14.3/testng-6.14.3.pom'.
> Received fatal alert: access_denied
Folder IdeaProjects/example2 has fully accesible for all users. When I run the command with --stacktrace option, the last "caused by" is:
... 106 more
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: access_denied
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)
Could it be problem with SSL certificate? I'm using proxy to connect to the web.
This is build.gradle file I'm using
plugins {
id 'java'
id 'idea'
}
group 'jetbrains'
version '1.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
//testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.testng', name: 'testng', version: '6.14.3'
// https://mvnrepository.com/artifact/io.rest-assured/rest-assured
//compile group: 'io.rest-assured', name: 'rest-assured', version: '3.1.0'
//testCompile group: 'io.rest-assured', name: 'rest-assured', version: '3.1.0'
}
Problem solved, thanks to stackoverflow.com/a/22666646/2987755. Following variables/properties must be set in gradle.properties file.
systemProp.http.proxyHost=$proxy
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=$proxy
systemProp.https.proxyPort=8080
Related
I got a project and it is built with gradle 6 or older version.
I've checked the other stakeoverflow discussion with compile/testCompile problem in gradle 7, and I change all the dependencies from compile/testCompile to api/testImplementation.
But it still doesn't work when I'm doing gradle build.
It still return with Configuration with name 'compile' not found
I've checked this:
Build error with gradle Could not find method testCompile()
What's the difference between implementation, api and compile in Gradle?
Here is my root gradle configuration:
buildscript {
repositories {
mavenCentral()
}
dependencies {
// https://github.com/google/protobuf-gradle-plugin
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
}
}
plugins {
id 'application'
id 'java'
id 'java-library'
id "com.google.protobuf" version "0.8.10"
}
group 'com.ght'
version '61'
mainClassName = 'com.application'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
// jcenter() is no longer support.
// jcenter()
mavenCentral()
}
sourceSets {
main {
proto {
srcDir 'src/main/protobuf'
include '**/*.protodevel'
}
}
}
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.0.0'
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.3'
// https://mvnrepository.com/artifact/ch.qos.logback/logback-core
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.1.3'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-implementation
implementation group: 'org.slf4j', name: 'slf4j-implementation', version: '1.7.26'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.2.1'
// https://mvnrepository.com/artifact/org.locationtech.jts/jts-core
implementation group: 'org.locationtech.jts', name: 'jts-core', version: '1.16.0'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
// https://mvnrepository.com/artifact/com.vividsolutions/jts
implementation group: 'com.vividsolutions', name: 'jts', version: '1.13'
// https://mvnrepository.com/artifact/com.google.guava/guava
implementation group: 'com.google.guava', name: 'guava', version: '19.0'
// https://mvnrepository.com/artifact/org.apache.commons/commons-math3
implementation group: 'org.apache.commons', name: 'commons-math3', version: '3.5'
// https://mvnrepository.com/artifact/commons-logging/commons-logging
implementation group: 'commons-logging', name: 'commons-logging', version: '1.2'
}
protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.0.0'
}
generatedFilesBaseDir = "$projectDir/gen"
}
clean {
delete protobuf.generatedFilesBaseDir
}
jar{
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes('Manifest-Version': archiveVersion, 'Main-Class': 'com.application')
}
exclude 'logback-test.xml'
exclude '**/schema/**'
exclude '**.proto'
}
Here is build error message:
A problem occurred configuring root project 'application'.
> Configuration with name 'compile' not found.
* Try:
> Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'application'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:84)
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:77)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:55)
at org.gradle.configuration.project.LifecycleProjectEvaluator$NotifyAfterEvaluate.run(LifecycleProjectEvaluator.java:255)
.
.
.
Caused by: org.gradle.api.artifacts.UnknownConfigurationException: Configuration with name 'compile' not found.
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.createNotFoundException(DefaultConfigurationContainer.java:108)
at org.gradle.api.internal.DefaultNamedDomainObjectCollection.getByName(DefaultNamedDomainObjectCollection.java:333)
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.getByName(DefaultConfigurationContainer.java:98)
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.getByName(DefaultConfigurationContainer.java:50)
.
.
.
at com.google.protobuf.gradle.ProtobufPlugin$_setupExtractIncludeProtosTask_closure21.doCall(ProtobufPlugin.groovy:369)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:73)
at org.gradle.util.internal.ConfigureUtil.configureTarget(ConfigureUtil.java:155)
at org.gradle.util.internal.ConfigureUtil.configureSelf(ConfigureUtil.java:131)
at org.gradle.api.internal.AbstractTask.configure(AbstractTask.java:666)
at org.gradle.api.DefaultTask.configure(DefaultTask.java:309)
.
.
.
gradle version: gradle 7.5
gradle JVM version: GraalVM version 17.0.3
IDE: intellij ide 2022.1.3
Thank you for any help.
You're using a very outdated version of the Protobuf Gradle plugin. Version 0.8.10 (2019) predates Gradle 7 (2021). The issue you're facing is likely to be fixed by upgrading the plugin.
plugins {
id "com.google.protobuf" version "0.8.19"
}
I am new to sonarqube and trying to execute a code scan on a java/jaxrs backend with gradle.
My build.gradle is the following:
buildscript {
dependencies {
classpath group: "com.liferay", name: "com.liferay.gradle.plugins", version: "4.4.5"
classpath group: "org.sonarsource.scanner.gradle", name:"sonarqube-gradle-plugin", version:"3.3"
}
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
}
apply plugin: "org.sonarqube"
apply plugin: "com.liferay.plugin"
dependencies {
compileOnly group: "javax.ws.rs", name: "javax.ws.rs-api", version: "2.1"
compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"
compileOnly group: "org.osgi", name: "org.osgi.service.jaxrs", version: "1.0.0"
compile group: 'com.liferay', name: 'com.liferay.portal.remote.cors.api', version: '1.0.4'
compileInclude group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compileOnly group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.5'
compileOnly group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.9'
compileOnly group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.5'
implementation group: 'com.liferay.portal', name: 'release.portal.api', version: '7.3.1-ga2'
implementation group: 'commons-lang', name: 'commons-lang', version: '2.6'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
//
implementation group: 'org.junit.platform', name: 'junit-platform-commons', version: '1.7.0'
testImplementation('org.junit.jupiter:junit-jupiter-api:5.4.2')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.2')
testCompile('org.junit.jupiter:junit-jupiter-params:5.4.2')
testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.7.0'
testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.7.0'
testCompile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
testImplementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.5'
testImplementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.9'
testImplementation group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.5'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
task copyJar(type: Copy) {
from "build/libs"
into "../../../../files/osgi/modules/"
}
copyJar.dependsOn(build)
repositories {
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
test {
useJUnitPlatform()
}
When I try to execute the sonar-scanner command from windows powershell or cmd:
.\gradlew sonarqube -Dsonar.projectKey=be_d254_enroll_center -Dsonar.host.url=http://localhost:9000 -Dsonar.login=1f774e64a98490b5e01646104342de340e40f263 -Dsonar.sources=src
I get the following error that points at another project be_256 different from the project from where I executed the command which is be_261
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':LR/rs/256/be_256'.
> Cannot add task 'downloadNode' as a task with that name already exists.
Config:
Sonarqube LTS 8.9.3
Gradle version 4.10.2
Java version 11
I tried to clear gradle cache but it did not work.
Any help is appreciated. Thanks.
Edit 1
I have been able to solve the previous error by completely uninstalling Gradle and re-installing it, I now have the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':LR/rs/261/be_261'.
> Could not resolve all artifacts for configuration ':LR/resident_services/d261_update_address/be_d261_update_address:classpath'.
> Could not download sonar-scanner-api.jar (org.sonarsource.scanner.api:sonar-scanner-api:2.16.1.361)
> Could not get resource 'https://repository-cdn.liferay.com/nexus/content/groups/public/org/sonarsource/scanner/api/sonar-scanner-api/2.16.1.361/sonar-scanner-api-2.16.1.361.jar'.
> Could not GET 'https://repository-cdn.liferay.com/nexus/content/groups/public/org/sonarsource/scanner/api/sonar-scanner-api/2.16.1.361/sonar-scanner-api-2.16.1.361.jar'.
> Received fatal alert: handshake_failure
Edit 2
I am once again stuck on this issue, I have tried once again to clear gradle's cache but it did not work
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':LR/rs/256/be_256'.
> Cannot add task 'downloadNode' as a task with that name already exists.
This issue was fixed after I moved the BE folder to another directory.
I have java project with gradle and spring boot that I want to deploy to Heroku.
I created myApp.war locally using gradle war (I have to deploy locally because I'm using a local lib repository). The war have been created with success, but when I tried to deploy to Heroku heroku war:deploy myApp.war --app appName, I received the error:
! ERROR: Your buildpacks do not contain the heroku/jvm buildpack!Add heroku/jvm to your buildpack configuration or run `heroku buildpacks:clear`.
! Re-run with HEROKU_DEBUG=1 for more info.
! There was a problem deploying to appName.
! Make sure you have permission to deploy by running: heroku apps:info -a appName
I'm using:
Java 10
Spring boot
Gradle 4
I have already add heroku/gradle build pack trough the heroku app settings.
build.gradle
plugins {
id 'java'
id 'idea'
id 'maven'
id 'war'
id 'application'
id 'org.springframework.boot' version '2.0.6.RELEASE'
}
mainClassName = "com.my.app.BootApplication"
war {
baseName = 'my-app'
version = '1.0.0'
}
logger.lifecycle "war.archivePath = $war.archivePath"
description = """My app description"""
sourceCompatibility = 10
targetCompatibility = 10
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
maven { url uri('../my-locally-private-repository') }
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'2.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'2.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web-services', version:'2.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version:'2.0.4.RELEASE'
compile 'com.github.jsimone:webapp-runner:8.5.11.3'
compile group: 'org.hamcrest', name: 'hamcrest-core', version:'1.3'
compile group: 'com.my.app, name: 'private-dependency-1', version:'1.0.0'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'2.0.4.RELEASE'
}
system.properties
java.runtime.version=10
Procfile
web: java -jar build/server/webapp-runner-.jar build/libs/.war
How can I solve this problem?
Run heroku buildpacks:clear like the error message says. The heroku/gradle buildpack is not used when you push a WAR file.
I am trying to execute a Grizzly HTTP Server inside a container.
Why i have this error, while running jar:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/grizzly/http/server/HttpServer
All was allright in maven with pom, but i met this error in gradle.
This is my build.gradle:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.13.0",
}
}
group 'com.mycompany'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'com.palantir.docker'
docker {
name "${project.group}/${jar.baseName}"
files 'build/libs'
buildArgs(['JAR_FILE': "${jar.archiveName}"])
}
jar {
manifest {
attributes 'Main-Class': 'com.mycompany.json_validator.Main'
}
baseName = 'JSON_validator-boot-docker'
version = '0.2.0'
archiveName = 'JSON_validator-boot-docker-0.2.0.jar'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.26'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-multipart', version: '2.7'
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.17'
compile group: 'org.glassfish.jersey', name: 'jersey-bom', version: '2.17', ext: 'pom'
}
All in all, i want to build jar for docker.
java.lang.NoClassDefFoundError:
org/glassfish/grizzly/http/server/HttpServer
NoClassDefFoundError indicates definition of the class could be found at the runtime, this could be missing jar/libraries. Make sure, you have included grizzly-http-server-x.x.x.jar and related jars in classpath.
I'm writing a Java program that runs from the command line and uses a library that I wrote to parse command line arguments. Since my library isn't on maven repository, I'm using flatDir in gradle to grab the jar from a directory local/ containing the jar file. Here is my build.gradle:
apply plugin: 'java-library'
repositories {
jcenter()
mavenCentral()
flatDir(dirs: 'local')
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:21.0'
testImplementation 'junit:junit:4.12'
// https://mvnrepository.com/artifact/javax.mail/mail
compile group: 'javax.mail', name: 'mail', version: '1.4.1'
// https://mvnrepository.com/artifact/org.mongodb/mongodb-driver
compile group: 'org.mongodb', name: 'mongodb-driver', version: '3.4.2'
// https://mvnrepository.com/artifact/org.jsoup/jsoup
compile group: 'org.jsoup', name: 'jsoup', version: '1.7.2'
// https://mvnrepository.com/artifact/log4j/log4j
compile group: 'log4j', name: 'log4j', version: '1.2.12'
// not in maven repository
compile 'JModule:JModule:1.3.1'
}
task copyToLib(type: Copy) {
from configurations.compile
into 'dependencies'
}
build.dependsOn(copyToLib)
My code runs fine in the eclipse IDE, and runs fine from the command line when I comment out all the references to JModule (my library) and run it with all the other libraries I'm using. However, when I run it with JModule as a dependency, it produces the following error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/jModule/def/CommandLogic
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.jModule.def.CommandLogic
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
I've already tried removing references to the class com.JModule.commandLogic but this only produces the same error with other JModule classes. Just to be clear, I'm not yet exporting to a jar - I'm just running the main class from the command line using the "java" command. The jar is also in the eclipse folder "project and external dependencies" so I'm assuming this means it's in my classpath, since the other jars in there run fine in my program.
Any help would be appreciated, thanks