Newbie, Lost, Confused, and Desperate...

Answered
All I am trying to do is add log4j to a barebones Gradle Project. 

THIS IS THE ENTIRE CODE, AND IT CAN'T GET ANY SIMPLER:
import org.apache.logging.log4j; // This namespace 'uses Log4j 2'

public class Main {
// I even commented this out:
//final static Logger logger = Logger.getLogger(Main.class);

public static void main(String[] args) {
System.out.println("ENTERED static main");
}
}

I get this error message where it echos my import statement shown above...

error: package org.apache.logging does not exist
import org.apache.logging.log4j; // This namespace 'uses Log4j 2'

I am using a MacBook Air (M1, 2020).

My build.gradle file...

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.apache.logging.log4j:log4j-api:2.17.2'
    implementation 'org.apache.logging.log4j:log4j-core:2.17.2'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
    useJUnitPlatform()
}

 

0
7 comments

Does it build via the command line Gradle outside of the IDE?

Does the Gradle import complete without errors in the IDE?

Any related errors in the logs? https://intellij-support.jetbrains.com/hc/en-us/articles/207241085.

0

Does it build via the command line Gradle outside of the IDE? 

ANSWER: Have no idea how to do this.

Does the Gradle import complete without errors in the IDE?

ANSWER: The 'importing' failure is the issue per the screenshot I submitted previously, assuming we are talking about the same issue to which you refer.

I viewed the idea.log file. I see some entries that are warnings, but are they are of no help to me. May I suggest you attempt what I am trying. If you're successful, great, otherwise we can close this as I am lost. I am convinced a simple Gradle app can't support log4j 2.

0

> ANSWER: Have no idea how to do this

gradlew build

in the system command line / terminal.

> ANSWER: The 'importing' failure is the issue per the screenshot I submitted previously, assuming we are talking about the same issue to which you refer.

The question was about the gradle project import / sync in the IDE.

>  May I suggest you attempt what I am trying.

Please zip and upload your project at https://uploads.jetbrains.com and provide the ID here.

0

Upload id: 2022_04_02_Vcnwk8NgAT58BLaE (files: GradleFive.zip, ID-3946901.txt)

0

Good luck! While I may be a newbie, I am a 77-year-old retired Software Development Manager who managed Windows and .NET/C# development.

Upload id: 2022_04_02_Vcnwk8NgAT58BLaE (files: GradleFive.zip, ID-3946901.txt)

0

The problem is not with IntelliJ IDEA, Gradle or the dependencies, the problem is with your code.

Please see https://logging.apache.org/log4j/2.x/manual/api.html for the example of working code.

This code builds without errors:

0

Thank you so much, Serge!!! You made my day!

0

Please sign in to leave a comment.