Gradle build error on previously working program - java

I have a Jave 8, SpringBoot, webService which has been running fine on Eclipse 2020-06 for months. I build using Gradle. In an attempt to get the latest version of an updated jar file from Artifactory I did :
gradlew clean
gradlew eclipse
F5 (Refresh)
This indeed pulled the required jar file but my program now failed to compile. The error is:
The import org.springframework.beans.factory.annotation cannot be resolved
And all my #Autowired commands now error.
What i've tried :
gradlew cleanEclipse eclipse
close project, close eclipse, reopen eclipse, reopen project
gradle -> Refresh Gradle project
Same a 2. preceded by reboot pc. When I do this I get:
After I did:
gradlew cleanEclipse eclipse
The following jar dissapeared from my project:
spring-beans.5.3.0.RC1.jar
This is what is causing the problem.
Is this incorrect in build.gradle:
implementation "org.springframework:spring-beans:5.+"
How do I get this jar back?
Any help appreciated.
My build.gradle file is:
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'java'
}
repositories {
maven {
url "https://repo-int.xxxxxx.io/artifactory/cc-central"
}
maven {
url "https://code.lds.org/nexus/content/groups/main-repo"
}
maven {
url "${chemaxonRepositoryUrl}/libs-release"
credentials {
username = chemaxonRepositoryUser
password = chemaxonRepositoryPassword
}
}
}
ext {
archive_basename = "dcrws"
project_description = "Chemistry Workbench DcrWs"
springStarterVersion = '2.2.2.RELEASE'
// Jenkins/Environment Information
build_tag = System.getenv('BUILD_TAG') ?: "none"
build_by = System.getenv('NODE_NAME') ?: "none"
build_date = System.getenv('BUILD_TIMESTAMP') ?: "none"
build_system = System.getenv('JENKINS_HOME') ?: "none"
build_url = System.getenv('BUILD_URL') ?: "none"
build_user = System.getenv('USER') ?: "none"
}
// standard plugins
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
def git_info = hasProperty('git_info') ? git_info : 'https://git.git/repo,00000000'
def full_version = hasProperty('app_version') ? app_version : '0.0.0'
group = 'com.clarivate.singularity.chemworkbench'
version = full_version
archivesBaseName = ext.archive_basename
sourceCompatibility = 1.8
targetCompatibility = 1.8
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
// if master branch, use latest version of chemcur:cwbcommon, else use 0.0+ version
ext.cwbcommon_version = '1.+'
if ( full_version =~ /^0./) { ext.cwbcommon_version = '0.0+' }
ext.pwbcommon_version = '1.+'
if ( full_version =~ /^0./) { ext.pwbcommon_version = '0.0+' }
dependencies {
implementation "org.springframework.boot:spring-boot-starter-actuator:$springStarterVersion"
implementation "org.springframework.boot:spring-boot-starter-web:$springStarterVersion"
implementation "org.springframework.boot:spring-boot-starter-cache:$springStarterVersion"
implementation "org.springframework.boot:spring-boot-starter-data-jdbc:$springStarterVersion"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:$springStarterVersion"
implementation "org.springframework.boot:spring-boot-starter-tomcat:$springStarterVersion"
implementation 'com.fasterxml.jackson.core:jackson-core:2.+'
implementation "org.springframework:spring-beans:5.+"
implementation "org.springframework:spring-core:5.+"
implementation "javax.servlet:javax.servlet-api:4.+"
implementation "org.apache.commons:commons-lang3:3.9+"
implementation "commons-dbutils:commons-dbutils:1.7+"
implementation "com.oracle:ojdbc6:11.2.0.1.0"
compile 'com.chemaxon:calculations:20.+'
// homegrown libs
compile ("chemcur:cwbcommon:${cwbcommon_version}") {changing = true}
compile ("chemcur:pwbcommon:${pwbcommon_version}") {changing = true}
developmentOnly "org.springframework.boot:spring-boot-devtools:$springStarterVersion"
}
springBoot {
buildInfo {
properties {
artifact = archive_basename
version = full_version
group = group
name = project_description
additional = [
'Implementation-Title': project_description,
'Implementation-Version': full_version,
"Implementation-SCM": git_info,
"Jenkins-Build-Tag": build_tag,
"Build-By": build_by,
"Build-Date": build_date,
"Build-JDK": System.getProperty('java.version'),
"Build-Gradle-Version": project.gradle.gradleVersion,
]
}
}
}

Related

facing issue with gradle install command: `java.lang.NoSuchMethodError: org.gradle.internal.jvm.inspection.JvmMetadataDetector.getMetadata `

I am trying to run gradle install. The goal is to convert to the gradle project to a mvn project. For that we have the mvn plugin as a part of gradle project.
gradle version is 7.6
java version is java 11
gradle build file:
plugins {
id 'java'
id 'idea'
id 'jacoco'
id 'maven-publish'
id 'com.diffplug.spotless' version '5.11.0'
id 'checkstyle'
id 'nebula.ospackage' version "8.3.0"
id "org.gradle.test-retry" version "1.3.1"
}
spotless {
java {
// note: you can use an empty string for all the imports you didn't specify explicitly, and '\\#` prefix for static imports
importOrder('java', 'javax', '', 'com.amazon', 'org.opensearch', '\\#')
}
}
java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11
tasks.withType(Checkstyle) {
showViolations true
reports {
ignoreFailures = false
}
}
tasks.withType(JavaCompile) {
configure(options) {
options.encoding = 'UTF-8'
options.compilerArgs << '-Xlint:removal' << '-Werror'
}
}
tasks.test.finalizedBy(jacocoTestReport) // report is always generated after tests run
tasks.jacocoTestReport.dependsOn(test) // tests are required to run before generating the report
allprojects {
tasks.withType(Javadoc).all { enabled = false }
}
bundlePlugin {
from('plugin-security.policy')
from('config') {
into 'config'
}
from('tools') {
into 'tools'
}
}
But facing the below issue:
org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:49)
Caused by: java.lang.NoSuchMethodError: org.gradle.internal.jvm.inspection.JvmMetadataDetector.getMetadata(Ljava/io/File;)Lorg/gradle/internal/jvm/inspection/JvmInstallationMetadata;
at
```

IntelliJ: Unresolved reference, but gradle build still succeeds

I have a Java library https://github.com/skycavemc/skycavelib which I want to use in a Kotlin project. This is the build.gradle where I have the library as dependency:
import java.util.Properties
import java.io.FileInputStream
plugins {
kotlin("jvm") version "1.7.10"
}
group = "de.skycave"
version = "1.0.0"
val localProperties = Properties()
localProperties.load(FileInputStream(rootProject.file("local.properties")))
repositories {
mavenCentral()
maven { url = uri("https://repo.papermc.io/repository/maven-public/") }
maven { url = uri("https://jitpack.io") }
maven {
url = uri("https://maven.pkg.github.com/skycavemc/skycavelib")
credentials {
username = localProperties.getProperty("gpr.user")
password = localProperties.getProperty("gpr.key")
}
}
}
dependencies {
implementation(kotlin("stdlib"))
compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")
implementation("de.skycave:skycavelib:1.0.2")
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
I also made sure I have a file named local.properties in my project where I set gpr.user and gpr.key correctly. The authentication works and the library is downloaded and indexed. IntelliJ also shows the library under "External Libraries".
When I try to use a class from that library, IntelliJ's autocompletion suggests the correct import. But after importing it, IntelliJ says "Unresolved reference" in the line of the import and the line where I use that class.
However, the gradle build still succeeds. Also, I only experience this issue when I import something from that library in a Kotlin class. In a Java class, IntelliJ can resolve the reference. This problem does not only happen in one specific project, but in all projects where I try to import something from that library, which means it's probably not an issue with the project configuration. The other Java library I use (paper-api) works fine when importing in both Kotlin and Java files. Invalidating caches and reloading all gradle projects has not solved the issue.
I suppose there is something misconfigured in my library https://github.com/skycavemc/skycavelib. Does someone have an idea what could have went wrong there? This is my build.gradle for the library I am trying to import from:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.7.10'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'maven-publish'
}
group = 'de.skycave'
version = '1.0.2'
def localProperties = new Properties()
localProperties.load(new FileInputStream(rootProject.file("local.properties")))
repositories {
mavenCentral()
maven {
name = 'papermc-repo'
url = 'https://repo.papermc.io/repository/maven-public/'
}
maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public/'
}
maven {
name = 'jitpack'
url = 'https://jitpack.io'
}
}
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10'
compileOnly 'io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT'
implementation 'org.mongodb:mongodb-driver-sync:4.7.1'
implementation 'com.google.code.gson:gson:2.9.1'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.11.0'
implementation 'com.github.heuerleon:mcguiapi:v1.3.5'
}
def targetJavaVersion = 17
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
manifest {
attributes 'Main-Class': "de.skycave.skycavelib.SkyCaveLib"
}
}
tasks.withType(JavaCompile).configureEach {
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
//noinspection GroovyAssignabilityCheck, GroovyAccessibility
options.release = targetJavaVersion
}
}
processResources {
def props = [version: version]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
expand props
}
}
build {
dependsOn(shadowJar)
}
shadowJar {
archiveFileName.set("${project.name}-${project.version}.jar")
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/skycavemc/skycavelib"
credentials {
username = localProperties.getProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
password = localProperties.getProperty("gpr.token") ?: System.getenv("ACCESS_TOKEN")
}
}
}
publications {
library(MavenPublication) {
from components.java
}
}
}
Solution
I did some more research and found a hint that shadowed jars might not work well. I removed this part
build {
dependsOn(shadowJar)
}
from the build.gradle of my library and published it to the package repository. Everything works fine since then, seems like that was the issue.

Web3j plugin for gradle task not found

I am beating against a wall for a whole week. I can't really see the reason why it doesn't work. I have a project where I want to run my Java project with the following build.gradle config:
plugins {
id 'java'
id 'org.springframework.boot' version '2.6.3'
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id 'org.web3j' version "4.8.4"
}
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
jcenter()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'com.suplab'
sourceSets {
main {
solidity {
srcDir "contracts"
}
}
test {
solidity {
srcDir "contracts"
}
}
}
ext {
web3jVersion = '4.8.4'
}
npmInstall {
enabled false
}
dependencies {
implementation "org.web3j:core:$web3jVersion"
implementation "org.web3j:web3j-evm:$web3jVersion"
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.hibernate:hibernate-core:5.6.5.Final'
}
I use gradle version 6.8, since it was specified by developer of the plugin. When I try to build this project from the parent, root folder that is the root of the project, it fails with following error:
A problem occurred configuring project ':api'.
> Failed to notify project evaluation listener.
> Task with name 'resolveSolidity' not found in project ':api'.
> Could not create task ':api:generateTestContractWrappers'.
> Task with name 'compileTestSolidity' not found in project ':api'.
I can't figure it out. I checked it against the build that being generated with web3j-cli, and it's the same for the configuration property (both configs have it blank). So, I don't see any reason WHY it fails. Here's the webj3-cli generated build file:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
id 'application'
id "com.github.johnrengelman.shadow" version "5.2.0"
id 'org.web3j' version '4.8.4'
}
group 'org.web3j'
version '0.1.0'
sourceCompatibility = 1.8
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
jcenter()
}
web3j {
generatedPackageName = 'org.web3j.generated.contracts'
excludedContracts = ['Mortal']
}
ext {
web3jVersion = '4.8.4'
logbackVersion = '1.2.3'
}
dependencies {
implementation "org.web3j:core:$web3jVersion",
"ch.qos.logback:logback-core:$logbackVersion",
"ch.qos.logback:logback-classic:$logbackVersion"
implementation "org.web3j:web3j-unit:$web3jVersion"
implementation "org.web3j:web3j-evm:$web3jVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}
jar {
manifest {
attributes(
'Main-Class': 'org.web3j.Web3App',
'Multi-Release':'true'
)
}
}
application {
mainClassName = 'org.web3j.Web3App'
}
test {
useJUnitPlatform()
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

No signature of method is applicable for argument types when trying to publish to JCenter with gradle

I'm trying to publish my project to JCenter with gradle.
I'm getting this error:
$ ./gradlew bintrayUpload
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/tomcaflisch/my-project/build.gradle' line: 32
* What went wrong:
A problem occurred evaluating root project 'my-project'.
> No signature of method: build_1izvkzzfcfkppgubyut54udzf.bintray() is applicable for argument types: (build_1izvkzzfcfkppgubyut54udzf$_run_closure3) values: [build_1izvkzzfcfkppgubyut54udzf$_run_closure3#30577a07]
* 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 1s
Here's my build.gradle file
buildscript {
repositories {
maven { url "https://repo1.maven.org/maven2" }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.+'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
plugins {
id "com.jfrog.bintray" version "1.8.5"
}
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'java'
group = 'com.projectx'
version = '0.0.1'
repositories {
jcenter()
mavenCentral()
}
sourceSets {
main.java.srcDirs = ['src/main/java']
}
bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
publications = ['MyPublication']
pkg {
repo = 'maven'
name = 'project-x'
userOrg = 'myorg'
licenses = ['Proprietary']
vcsUrl = 'https://github.com/myorg/my-project.git'
version {
name = project.version
released new Date()
}
}
}
publishing {
publications {
MyPublication(MavenPublication) {
from components.java
groupId project.group
artifactId 'projectx'
version project.version
}
}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'jacoco'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
install {
repositories.mavenInstaller {
pom.artifactId = 'projectx'
}
}
test {
finalizedBy jacocoTestReport // Report is always generated after tests run
}
jacocoTestReport {
dependsOn test // Tests are required to run before generating the report
reports {
xml.enabled true
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
dependencies {
compile 'io.swagger:swagger-annotations:1.5.22'
compile "com.google.code.findbugs:jsr305:3.0.2"
compile 'com.squareup.okhttp3:okhttp:3.14.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.14.2'
compile 'com.google.code.gson:gson:2.8.5'
compile 'io.gsonfire:gson-fire:1.8.3'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
testCompile 'junit:junit:4.13'
testCompile 'org.mockito:mockito-core:3.+'
testImplementation "com.google.truth:truth:1.0.1"
}
javadoc {
options.tags = [ "http.response.details:a:Http Response Details" ]
}
Bintray is dead.
But to answer the question, No signature of method: build_whatever.[method]() comes from something in the configuration of [method] being incorrect. In this case I'd guess it's caused by released new Date() which should probably be released = new Date()

Gradle artifactoryPublish is Skipped

I am trying to publish war files to our local artifactory server but when I run:
./gradlew clean build artifactoryPublish
I receive the following output:
:zuul-netflix-webapp:artifactoryPublish
Skipping task ':zuul-netflix-webapp:artifactoryPublish' as task onlyIf is false.
:zuul-netflix-webapp:artifactoryPublish SKIPPED
I've tried manually setting the onlyIf to true but this had no effect. I have tried similar configuration on another project and it works fine.
My environment:
17:22 $ ./gradlew --version
------------------------------------------------------------
Gradle 3.5.1
------------------------------------------------------------
Build time: 2017-06-16 14:36:27 UTC
Revision: d4c3bb4eac74bd0a3c70a0d213709e484193e251
Groovy: 2.4.10
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_141 (Oracle Corporation 25.141-b15)
OS: Mac OS X 10.11.6 x86_64
My build.gradle file looks like:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.netflix.nebula:gradle-extra-configurations-plugin:2.2.0'
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
classpath 'org.akhikhl.gretty:gretty:2.0.0'
}
configurations.classpath {
resolutionStrategy {
cacheDynamicVersionsFo r 0, 'seconds'
cacheChangingModulesFor 0, 'seconds'
}
}
}
plugins {
id 'nebula.netflixoss' version '3.4.0'
}
ext.githubProjectName = rootProject.name
configurations.all {
// Exclude old asm 3.x versions.
exclude group: 'asm', module: 'asm'
exclude group: 'asm', module: 'asm-all'
}
allprojects {
apply plugin: 'java'
group = "com.netflix.${githubProjectName}"
version = currentVersion
//status = 'Integration'
}
artifactoryPublish.skip = true
subprojects {
artifactoryPublish.skip = false
//artifactoryPublish.onlyIf { true }
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'ivy-publish'
apply plugin: 'war'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'nebula.netflixoss'
apply plugin: 'nebula.provided-base'
dependencies {
testCompile 'junit:junit:4.7'
}
repositories {
jcenter()
}
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
sourceSets.test.java.srcDir 'src/main/java'
tasks.withType(Javadoc).each {
it.classpath = sourceSets.main.compileClasspath
}
test {
forkEvery = 1
maxParallelForks = 1
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.web
}
}
}
artifactoryPublish {
skip = false
publications(publishing.publications.mavenJava)
}
}
artifactory {
//clientConfig.setIncludeEnvVars(true)
//clientConfig.info.addEnvironmentProperty('test.adding.dynVar',new java.util.Date().toString())
contextUrl = 'https://artifactory.oss.central1.com/artifactory'
publish {
repository {
repoKey = 'libs-snapshot-local' // The Artifactory repository key to publish to
username = "${artifactory_user}" // The publisher user name
password = "${artifactory_password}" // The publisher password
ivy {
ivyLayout = '[organization]/[module]/ivy-[revision].xml'
artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]'
mavenCompatible = true //Convert any dots in an [organization] layout value to path separators, similar to Maven's groupId-to-path conversion. True if not specified
}
}
defaults {
// Reference to Gradle publications defined in the build script.
// This is how we tell the Artifactory Plugin which artifacts should be
// published to Artifactory.
publications('mavenJava')
}
}
resolve {
repoKey = 'jcenter'
}
}

Categories

Resources