Could not able resolve javax.inject: javax.inject:1.0 - Gradle - gradle

I am getting below error while running Gradle build in Unix terminal.
Could not resolve all files for configuration ':imcalmsvc-service:compileClasspath'.
Could not find javax.inject:javax.inject:1.0.
Searched in the following locations:
- https://jcenter.bintray.com/javax/inject/javax.inject/1.0/javax.inject-1.0.pom
- https://repo.maven.apache.org/maven2/javax/inject/javax.inject/1.0/javax.inject-1.0.pom
However, there is no error while doing Eclipse-> Gradle refresh.

The error means the dependency wasn't found in either JCenter or Maven Central. When you are usure about the exact name of dependency or which repositories it is uploaded to, I recommend a search engine like mvnrepository.com. It aggregates metadata from a lot of different Maven repositories and even shows you how to use them in Gradle.
In your case, you can find the javax.inject library here. Notice that the only published version is simply 1 and not 1.0. Change this and it should work.

Related

AEM Mocks missing artifact for latest version

I have added the latest version of AEM Mocks (2.7.2) as a Maven dependency in my AEM project. When I try to build my project, I get an error saying that this artifact cannot be found: com.day.commons:day-commons-gfx:jar:2.1.28. So I looked online, found it and added it as a dependency. But now I get the same error when trying to build. Does this artifact still exist? When trying various recent versions of AEM Mocks, I found that they all depend on this missing artifact.
For now, I downgraded to version 2.3.0, which works fine without that artifact but I would like to use the most recent version if possible.
Can anyone please help? Thanks!
This artifact is defined as a workaround, it is explained here in comment:
https://github.com/wcm-io/wcm-io-testing/blob/develop/aem-mock/core/pom.xml#L254:
Workaround for AEM 6.5: The new uber-jar does no longer contain the package com.day.imageio.plugins
It works without any issues for me, so I would check if you have correctly configured Maven repositories. To do it, in your Maven project root type:
mvn help:evaluate
and then:
${project.repositories}
It should list your project effective repositories. Ensure that there is Central Repository (https://repo.maven.apache.org/maven2/) listed. If it is there, then maybe your corporate network cuts requests to external repositories or it was temporarily down.

Adding org.apache.kafka to dependencies with Gradle

I started a Gradle project with gradle init --type java-application using Kotlin as the build script DSL, and I just wanted to add org.apache.kafka library
dependencies {
// This dependency is used by the application.
implementation("com.google.guava:guava:28.0-jre")
implementation("org.apache.kafka:kafka_2.10:0.8.0")
// Use JUnit test framework
testImplementation("junit:junit:4.12")
}
But gradle build returned this:
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find jmxtools.jar (com.sun.jdmk:jmxtools:1.2.1).
Searched in the following locations:
https://jcenter.bintray.com/com/sun/jdmk/jmxtools/1.2.1/jmxtools-1.2.1.jar
> Could not find jmxri.jar (com.sun.jmx:jmxri:1.2.1).
Searched in the following locations:
https://jcenter.bintray.com/com/sun/jmx/jmxri/1.2.1/jmxri-1.2.1.jar
What's this about? Conflicts with JCenter?
As already mentioned in the comments upgrading the kafka version will solve the problem (probs go to #cricket_007).
The root cause for that problem is actually not kafka itself but it's transitive dependency log4j in a version 1.2.15. This log4j version requires jmxtools and jmxri. Due to some licensing issues these artifacts are NOT available on maven central and jcenter. The good news is: You most likely don't need it at all. You simply override the log4j dependency to use 1.2.16 (or above) or exclude jmxtools and jmxri.
You can also find some more insights in this blog article: http://unitstep.net/blog/2009/05/18/resolving-log4j-1215-dependency-problems-in-maven-using-exclusions/
So 3 ways to solve this issue:
use a more recent kafka-version OR
use a log4j version > 1.2.15 OR
exclude jmxtools and jmxri
Hope that helps and make things more clear

can't find my maven artifacts

I'm working in eclipse and I have a problem that I can't import my personal java libraries.
I created the libraries and 'installed' them into my local maven repo (using mvn install). This created a subdirectory related to the 'version' name that was in the POM file from when I ran the command. Which seemed fine.
So in this directory there where the usual jar files and other stuff.
When I released this file I manually changed the name of the version in the POM. going from 0.0.1-SNAPSHOT to 0.0.1-RELEASE
This seems to have worked as I would have expected.
However I can't seem to find import the new release jar.
Using the maven repositories browser in eclipse I can see that the new artifact is in the 'local' repository.
I try to add the dependency in the following methods:
Select the main project -> Maven -> add dependency.
This adds the dependency details into the pom but with a type value detail of <type>pom.lastUpdated</type>
Select the project pom.xml file -> Maven -> add dependency.
This time the artifact for the 0.0.1-RELEASE is greyed out I can select it, but I guess nothing is actually happening.
The original 0.0.1-SNAPSHOT it selectable, and if I use this I do not have a <type> detail in the pom.
I don't understand why there is a difference in the RELEASE and SNAPSHOT artifacts, as they have both been generated in the same way, and clearly they are both visible in the browser, the contents of the directory on disk are the same. The file names and contents are identical with the exception of the word RELEASE or SNAPSHOT.
I know that I can simply add in the RELEASE jar to my build path, but this seems to be a ridiculous thing to have to do if I intend to use maven (or do I need to do this).
I don't want to use an external repo for storing my artifacts, and I'm not too keen to go to the trouble of installing nexus (or similar) on my local machine (just because I've had trouble with it in the past).
What am I missing so as I can get my maven project to see my local repository and all its artifacts.
Thanks in advance.
David
ps I've already tried things such as mvn dependency:purge-local-repository which definitely pulled in / updated all the local jar dependencies.
So I've managed to work around my problem.
As such this solution is ridiculous, and breaks all the purpose of maven.
So I found (from running maven from the cli) that there was an error in the parent of the project I was attempting to use.
The parent was missing a direct link to the scm plugin (version error).
Once I solved this problem, I then returned to the sub project, and got a lot of errors from missing stuff from the parent.
Essentially it was not 'seeing' all the log4j dependencies.
The solution (well non-solution really).
Add all the log4j dependencies to the sub project.
Edit in SCM and surefire test plugins (as it also started to fail the test code due to missing junit).
So this is great.
I have to define all my dependencies on log4j and in my sub / child project's pom.xml file.
I also need to define them all in my parent's pom.
As it then still refused to run tests in my new project (that used the above as a dependency), and refused to find log4j also. I then decided to add all of these as dependencies for my current project.
Great.
I thought the whole point of maven was I could define my dependency on log4j in my my logging library that I use (which is the dependency), and then it would 'automagically' pull in all the required from this dependency.
Clearly not.
As stated at the start. This is NOT AN ANSWER it is a crazy work around.
My logging library that I use should be able to define its own requirement on a specific log4j version (such as moving from log4j to log4j2), and then when I include this as a maven dependency any change to the required dependency should be seen automatically.
But No : I have to import the dependency on log4j in my other projects also. So now if I had updated my logging library from log4j to log4j2 I would need to go to all my project that use this library and update their pom's to ensure that I have the correct version of log4j.
Seems the whole point of maven has just been lost!
Can someone please tell me where I am going wrong!
David.

Download latest release from Artifactory with Gradle

Artifactory has a feature of their API where you can download the latest release of a jar file (See http://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-RetrieveLatestArtifact).
Their example is:
GET http://localhost:8080/artifactory/ivy-local/org/acme/[RELEASE]/acme-[RELEASE].jar
I'm working on a project where all builds get published and I want to grab the jar from the last one. So what I'm looking for is a dependency like this in gradle:
compile "org.acme:acme:1.0.0.9.[RELEASE]"
This fails due to escaping of the square brackets so I tried:
compile "org.acme:acme:1.0.0.9.%5BRELEASE%5D"
This seems to allow gradle/ivy to find the file but it fails because the .pom file version does not match what is defined.
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':project:compile'.
> Could not resolve org.acme:acme:1.0.0.9.%5BRELEASE%5D.
Required by:
org.acme:acme:unspecified
> Could not resolve org.acme:acme:1.0.0.9.%5BRELEASE%5D.
> inconsistent module metadata found. Descriptor: CachedResource: /Users/xxxx/.gradle/caches/artifacts-26/filestore/org.acme/acme/1.0.0.9.%5BRELEASE%5D/pom/3986d9c1a27873ce92c0dbd089fc1ca9618f8c1a/acme-1.0.0.9.%5BRELEASE%5D.pom for http://localhost/artifactory/org/acme/acme/1.0.0.9.%5BRELEASE%5D/acme-1.0.0.9.%5BRELEASE%5D.pom Errors: bad version: expected='1.0.0.9.%5BRELEASE%5D' found='1.0.0.9.80'
Is there any way to get gradle and ivy to pull the latest release from artifactory?
I was able to get this working using the ivy syntax:
compile "org.acme:acme:1.0.0.9.+"
This solves the problem I have but I never did manage to get it working using the Artifactory [RELEASE] url.

Maven Could not resolve dependencies

Now, i have a project which runs fine on my windows computer. But after I copied it to a linux computer, when compiling it reports following error:
Failed to execute goal on project alert: Could not resolve dependencies for project com.cloud.ras:alert.
The POM for com.external:commons-logging:jar:1.0.4.1 is missing, no dependency information available
The POM for com.external:freemarker:jar:2.3.4 is missing, no dependency information available
The POM for com.external:log4j:jar:1.2.14 is missing, no dependency information available
The POM for com.soa.lib:eBoxServiceCommon:jar:2.5.3 is missing, no dependency information available
but i have copied these jars to the maven repository. And can anyone give me a help?
You should NOT copy JARs in the first place. That's Maven job to resolve the dependencies for you.
It would be helpful if you explain the reason why you need to use your own groupId e.g. com.external in the first place i.e. commons-logging is from Apache but you use com.external as its groupId.
If you really insist on wanting to use your own groupId, at least download the JAR and install it using Maven. See here:
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html.

Resources