I am trying to create a new maven (3.0.3) plugin based on an existing (2.0) plugin, and facilitating aether to pickup some dependencies.
I tried to create a simple test to load the mojo using the maven-plugin-testing-harness (version 2.0.1), but lookupMojo fails with a guice exception:
1) Error injecting: org.sonatype.aether.impl.internal.DefaultRepositorySystem
at ClassRealm[plexus.core, parent: null]
at ClassRealm[plexus.core, parent: null]
while locating org.sonatype.aether.RepositorySystem
while locating org.codehaus.griffon.maven.plugin.MvnValidateMojo
at ClassRealm[plexus.core, parent: null]
while locating org.apache.maven.plugin.Mojo annotated with #com.google.inject.name.Named(value=org.codehaus.griffon:griffon-maven-plugin:1.3.0-SNAPSHOT:validate)
This of course is because I need to reference the repository system at some point, but not right now:
#Component
private RepositorySystem repoSystem;
I have tried (actually started with) version 2.1, but got the problem in the AbstractMojoTestCase#setUp() method.
org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
role: org.apache.maven.repository.RepositorySystem
roleHint:
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:247)
Either way, Not sure what I need to include and where to do a vanilla mojo load test similar to the cookbook. Anybody got any ideas?
7 years later and I am hitting the same issue.
The solution is to also add the maven-compat artifact as test scoped dependency as the maven-plugin-testing-harness is apparently still relying on the old Maven 2 API.
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>[REQUIRED_MAVEN_VERSION_HERE]</version>
<scope>test</scope>
</dependency>
Kudos to user smoke for his answer here https://stackoverflow.com/a/16707144/5116073
Related
In a spring boot project who use maven. A class is not found
A part of my pom
<groupId>com.acme.pay</groupId>
<artifactId>ms.billing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ms.billing</name>
<packaging>jar</packaging>
<properties>
<default.package>com.acme.pay.ms.billing</default.package>
</properties>
Structure of the project
com
acme
pay
ms
billing
domain
v2
BillingServiceApplication.java
When I start application, I get this error
Error: Could not find or load main class com.acme.pay.ms.BillingServiceApplication
Caused by: java.lang.ClassNotFoundException: com.acme.pay.ms.BillingServiceApplication
Command execution failed.
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:exec (default-cli) on project ms.billing: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
It seem it don't seem in the correct path.
Your problem might be related to your artifactId having a . character in it. I've never seen an artifactId formatted like that and I think it might be messing up the path resolution. Usually people use - as a separator when they want to make an artifactId more readable (as per commons-math in the maven guide linked below).
http://maven.apache.org/guides/mini/guide-naming-conventions.html
choose whatever name you want with lowercase letters and no strange symbols
Can you please confirm if your application is 'Spring Boot' application?
If yes, then while running your application as 'Java application', just choose the main file as 'BillingServiceApplication'. There is no problem with your pom file.
If no, then could you please share your pom file with all dependencies?
I think that you need to change the version of the following dependency
'org.codehaus.mojo:exec-maven-plugin'.
Just check the link for similar question on stackoverflow:
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:java (default-cli)
I hope this helps!
did you annotate your class with #Component, #Services etc
OR
if your class out of the scan scoop you could included it via
#ComponentScan(basePackages = "com.acme.pay.ms.billing")
#Configuration
public class SpringComponentScanApp {
Or you could use xml as in your case via
<context:component-scan base-package="com.acme.pay.ms.billing" />
Package of BillingServiceApplication should be com.acme.pay.ms.billing.BillingServiceApplication
I work on a multi module maven project with osgi bundles deployed to karaf. We are observing intermittent bundle start-up issues in our test and production environments due to the below error, which is later resolved after restarting the karaf container:
Caused by: org.osgi.framework.BundleException: Uses constraint violation. Unable to resolve resource myBundle [myBundle [16](R 16.0)] because it is exposed to package 'javax.el' from resources javax.el-api [javax.el-api [236](R 236.0)] and com.sun.el.javax.el [com.sun.el.javax.el [212](R 212.0)] via two dependency chains.
Chain 1:
myBundle [myBundle [16](R 16.0)]
import: (&(osgi.wiring.package=javax.el)(version>=3.0.0)(!(version>=4.0.0)))
|
export: osgi.wiring.package: javax.el
javax.el-api [javax.el-api [236](R 236.0)]
Chain 2:
myBundle [myBundle [16](R 16.0)]
import: (&(osgi.wiring.package=com.sun.el)(version>=3.0.0)(!(version>=4.0.0)))
|
export: osgi.wiring.package: com.sun.el; uses:=javax.el
export: osgi.wiring.package=javax.el
com.sun.el.javax.el [com.sun.el.javax.el [212](R 212.0)] Unresolved requirements: [[myBundle [16](R 16.0)] osgi.wiring.package; (&(osgi.wiring.package=com.sun.el)(version>=3.0.0)(!(version>=4.0.0)))]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)[org.apache.felix.framework-5.4.0.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)[org.apache.felix.framework-5.4.0.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)[org.apache.felix.framework-5.4.0.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)[org.apache.felix.framework-5.4.0.jar:]
at org.apache.karaf.features.internal.service.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:1286)[10:org.apache.karaf.features.core:4.0.7]
at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:846)[10:org.apache.karaf.features.core:4.0.7]
... 6 more
I went through these 2 related SO posts (Error starting bundle in karaf: "via two dependency chains" and Why are uses constraints violated when both chains end in the same bundle? ) but in my situation I am actually unable to determine where from the javax.el-api dependency is being introduced to myBundle. Our project uses Hibernate Validator, which requires the EL package from glassfish jar, so this is where the com.sun.el.javax.el package dependency is introduced. I was unable to determine where the javax.el-api dependency is being introduced from though. I tried checking the dependency tree using the below maven commands but to no avail.
mvn compile dependency:tree
mvn compile dependency:tree -D:verbose
mvn compile dependency:tree -D:verbose -Dincludes=javax.el
This is the dependency added for hibernate validator:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b08</version>
</dependency>
The karaf version being used is 4.0.7
Any help will be appreciated.
Background:
I am developing Maven multi module project.
One of the module is common module needed by other all modules.
This module contain CommonClassA.java.
common module is properly compiled.
It is installed into maven local repository properly.
One of the class(Billtype.java) in other module (EmployeeBilling) refers this class(CommonClassA.java).
Maven Dependency for common module is properly specified in pom.xml of EmployeeBilling module.
Problem:
While compiling EmployeeBilling module it throws
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project EmployeeBilling: Compilation failure
[ERROR] \MyWorkspace\Biz\EmployeeBilling\src\main\java\com\employee\Billtype.java:[79,19] error: cannot access CommonClassA
[ERROR] -> [Help 1]**
Supporting details:
dependency defined in EmployeeBilling> pom.xml:
Other classes from common module seems accessible as no error observed
There are no other errors like Class not found/file not found.
The class CommonCLassA implements Serializable
Same error occurs from Eclipse as well as commond line
I am using M2E plugin
Tools:
jdk1.7.0_02
OS: Windows 7
Eclipse JUNO and apache-maven-3.1.0
Thanks in advance!
If project builds properly using eclipse compiler then it should work with Maven.
Few things to check if its not working with maven:
Manually check in repository that jar is installed properly and it contains your class file.
Try to build project using locally installed Maven instead of maven in eclipse.
Set -DskipTest=true while installing your jar, as it can cause issues at times.
If these steps don't work then show us your pom.
With no more information it's hard to find the cause. But I also had this problems now and then, and there are some things which could go wrong:
Are you using the right JAVA version (everywhere) ?
... and the right java PROVIDER? (Oracle, IBM, OpenJDK) In my case it's often this issue, I'm sometimes bound to IBM JDK, although I try to use Oracle where I can and this sometimes breaks my build.
Is the right maven dependency VERSION used? If you depend on it multiple times, and all in the same (lower than root) dept of dependencies, Maven will just "choose" a version. It could be that thát version is incompatible with your code of thát particular dependency
Skipping tests sometimes WORKS! It has something to do with maven phases and getting stuff ready for using it elsewhere.
Good luck :)
I had the same problem. Even the jar dependency has the required class files. Finally I deleted the local maven repo and restarted the build. Now it worked without any issue.
It looks like you are using an old version of maven-compiler-plugin (v2.3.2).
I suggest you upgrade it to 3.x. it won't magically fix your issue but it will definitely give you better / more detailed error message.
I am new to m2eclipse, and I created a dummy java project (mytest4) and checked enable dependency management, after that, the plugin created a pom.xml file. I manually added parent information, such as groupId, artifactId and version, etc. to the dummy project. Then I added modules to the parent project, and the parent projectType is pom not jar. However, when I build using clean install, I get an error:
[DEBUG] Extension realms for project com.multimod:myproject:pom:0.0.1-SNAPSHOT: (none)
[DEBUG] Looking up lifecyle mappings for packaging pom from ClassRealm[plexus.core, parent: null]
[ERROR] The build could not read 1 project ->
[Help 1]org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[ERROR] Child module C:\workspace\myproject\mytest4 of C:\workspace\myproject\pom.xml does not exist #
[ERROR] The project com.multimod:myproject:0.0.1-SNAPSHOT(C:\workspace\myproject\pom.xml) has 1 error
[ERROR] Child module C:\workspace\myproject\mytest4 of C:\workspace\myproject\pom.xml does not exist
I don't understand C:\workspance\myproject\pom.xml does not exist.
Could you give some hints?
Thank you.
You probably have to set the relative path to you parent pom file in the mytest4 pom file. The default is ../pom.xml hence your path C:\workspace\myproject\pom.xml.
As to your sub question in the comment. Right click on the project en select Configure > Convert to Maven Project
I'm trying to upgrade a Nexus server from version 1.7.2 to the latest, 1.9.2. I'm using the war distribution on my own Tomcat installation (Tomcat 6.0.18, Sun Java 1.6.0_14, on Linux).
What I've done is undeployed the old version of the webapp , and then deployed the new version of nexus.war (via Tomcat's HTML manager). This all seems to go fine, the webapp gets deployed, but when I then try to access it I get a 500 Internal Server Error.
Looking in the nexus logs, I see the following messages:
2011-08-10 23:57:42 WARN [http-8080-4 ] - o.s.g.b.r.LoadedCla~ - Error injecting: org.sonatype.nexus.plugins.mac.api.MacRepositoryPlexusResource
java.lang.NoClassDefFoundError: org/sonatype/nexus/index/ArtifactInfoFilter
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getDeclaredConstructors(Class.java:1836)
at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:243)
at com.google.inject.internal.ConstructorBindingImpl.create(ConstructorBindingImpl.java:96)
at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:628)
(....)
and
2011-08-10 23:57:42 ERROR [http-8080-4 ] - o.a.c.c.C.[.[.[/nex~ - nexus: Error during the starting of the Restlet Application
com.google.inject.ProvisionException: Guice provision errors:
1) Error injecting: org.sonatype.nexus.plugins.mac.api.MacRepositoryPlexusResource
at ClassRealm[org.sonatype.nexus.plugins:nexus-archetype-plugin:1.0.1-SNAPSHOT, parent: ClassRealm[plexus.core, parent: null]]
while locating org.sonatype.plexus.rest.resource.PlexusResource annotated with #com.google.inject.name.Named(value=org.sonatype.nexus.plugins.mac.api.MacRepositoryPlexusResource)
1 error
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:977)
at com.google.inject.Scopes$1$1.get(Scopes.java:59)
at org.sonatype.guice.bean.locators.LazyBeanEntry.getValue(LazyBeanEntry.java:79)
at org.sonatype.guice.plexus.locators.LazyPlexusBean.getValue(LazyPlexusBean.java:53)
(...)
I have googled around a bit to see if this is a known problem but couldn't really find anything... Has anyone experienced a similar problem when upgrading Nexus, and/or know what to do about it?
Found the answer to this (via the Sonatype community forum): I had an old nexus-archetype plugin installed (located in sonatype-work/nexus/plugin-repository). Apparently this functionality now ships with Nexus itself. Removing the plugin fixed the problem.