2

I was trying to build a jar file. Basically trying to dockerize my project. But I was unable to create a jar file. I was getting error. While I was running ./gradlew build I was getting the error:

l (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x7fd2416f

So, I ran gradle --stacktrace, then the following reason of error showed up:

e=log4j-api, version=2.14.1}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

build.gradle

plugins {
    id 'org.springframework.boot' version '2.5.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'org.projects'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '15'
def versionLog4j = '2.14.1'
def versionLombok = '1.18.20'
repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: versionLog4j
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: versionLog4j
    compile group: 'org.projectlombok', name: 'lombok', version: versionLombok
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: versionLombok
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'org.postgresql:postgresql'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

Java version

java 16.0.1 2021-04-20
Java(TM) SE Runtime Environment (build 16.0.1+9-24)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)

gradle -v


------------------------------------------------------------
Gradle 7.1.1
------------------------------------------------------------

Build time:   2021-07-02 12:16:43 UTC
Revision:     774525a055494e0ece39f522ac7ad17498ce032c

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          16.0.1 (Oracle Corporation 16.0.1+9-24)
OS:           Windows 10 10.0 amd64

Additionally, I have a warning which I can not fix: Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.

Deepjyoti De
  • 117
  • 1
  • 11

2 Answers2

1

Can You Run the Gradle build with a command line argument --warning-mode=all to see what exactly the deprecated features were used in your build ?

Divakar
  • 51
  • 5
  • ```FAILURE: Build failed with an exception.``` – Deepjyoti De Jul 09 '21 at 08:46
  • * What went wrong: A problem occurred evaluating project ':Assignment-14a'. > Could not find method compile() for arguments [{group=org.apache.logging.log4j, name=log4j-api, version=2.14.1}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies. DefaultDependencyHandler. – Deepjyoti De Jul 09 '21 at 08:46
  • 2
    Based on my understanding Compile() method is removed from Gradle 7.0, Read the Details here https://stackoverflow.com/questions/23796404/could-not-find-method-compile-for-arguments-gradle You need to use the implementation method instead of compile() – Divakar Jul 09 '21 at 10:11
  • I ran ```docker build -f /Assignment-14a/Dockerfile -t dockerstoreimage .``` and this is the thing showing up: ```Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them``` – Deepjyoti De Jul 09 '21 at 11:05
  • is the Dependency Issue fixed? I have no idea about Dockers. Let me try something – Divakar Jul 09 '21 at 11:57
  • well, I just used implement instead of compile and it worked. But now I am facing another issue. – Deepjyoti De Jul 09 '21 at 18:20
0

Instead of

dependencies {
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: versionLog4j
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: versionLog4j
}

use:

dependencies {
    implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.14.1'
    implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.14.1'
}
Boris
  • 1
  • 1