OpenShift, Log4j2 & Maven - Could not resolve depe

2019-06-11 06:55发布

问题:

I have created and run a stand-alone Java program that logs via Log4j2 using Slf4j. The logging worked as expected.

I then added this functionality to an existing (and working) OpenShift Java web application that I am developing in an Eclipse IDE.

I added the following dependencies to pom.xml

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.21</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.7</version>
    </dependency>

I used a simple log4j2.xml configuration file and added some logging code to a Java class.

I ran the web application locally and the logging worked fine.

I then moved pom.xml and log4j2.xml to the Git Staging Area and did a Commit and Push. This normally works fine and there are no problems.

This time I got the following error message in the dialog console window:

[ERROR] Failed to execute goal on project testdb: Could not resolve dependencies for project testdb:testdb:war:1.0: Failure to find org.apache.logging.log4j:log4j-api:jar:2.7 in http://maven.repository.redhat.com/techpreview/all was cached in the local repository, resolution will not be reattempted until the update interval of eap has elapsed or updates are forced -> [Help 1]

It seems to be saying that log4j-api version 2.7 is not available in the RedHat Maven Repository. But I am surely not the first person to do this, so I suspect there is some underlying error.

Any ideas? Any help would be much appreciated...

回答1:

Hope this is timely and helpful. I was able to force an update and resolve this issue by deleting the invalid locally cached dependency in ~/.m2/repository/path/to/your/dependency on OpenShift, and then initiating another git push to trigger maven build.



回答2:

I have the SAME PROBLEM with RedHat Maven Repository on my current project.

To esclude all possible problem due to code of my current project, I created a new project and applied to it a little update on index.html file (I simply added a space character). Then, after a "git push" command, I obtained the same error on remote build phase, but this time with the download of basic plugin maven-clean-plugin :

remote: [ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 
or one of its dependencies could not be resolved: Failed to read artifact
descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1:
Failure to find org.apache.maven.plugins:maven-clean-plugin:pom:2.4.1 in
http://mirror.ops.rhcloud.com/nexus/content/groups/public was cached in the
local repository, resolution will not be reattempted until the update
interval of nexus has elapsed or updates are forced -> [Help 1]

It's clear that OPENSHIFT platform had some problem since today.



回答3:

Yesterday, I tried this and it worked for me:

Create an empty file called force_clean_build inside application .openshift/markers directory. Commit the file and push the changes. This will remove the .m2 repository and download all the dependencies and plugins again.