How to make M2E eclipse plugin understand Bundle packaging - bundle

I'm almost new with Osgi.
I'm using Eclipse 3.6 Helios for building my first Felix Bundle but find out that M2E don't understand bundle packaging...
Project build error: Unknown packaging: bundle
Project build error: Unresolveable build extension:
Plugin org.apache.felix:maven-bundle-plugin:2.0.0 or one of its dependencies could not be resolved:
Failed to collect dependencies for org.apache.felix:maven-bundle-plugin:jar:2.0.0 ()
As I done google searches, it was an error in Maven 2 but fixed in Maven 3 with M2E using.
Also, I'm using Window XP and under a proxy, which I think I sussefully config it, other connections in Eclipse work fine...
So I don't know how to get M2E understand bundle packaging ?

Using these settings, import the maven project. If there are missing connectors (which links maven goals and eclipse plugins), the 'Next' button should be enabled. Do Next and auto-resolve the connectors to install tycho plugins. From now on, your project will have a Plugin nature.
P.S Be sure to at least have one class to compile in the project or maven-bundle-plugin will complain.
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
</plugin>
</plugins>

Justy FYI, ebelanger's answer above led me down the right direction. If you're not seeing the eclipse popup prompting for resolving connections, you need to add the parent pom that declares the plugin to eclipse.
In my case I had a child pom project I was importing into eclipse (but not the parent pom). Note that the actual plugin decleragion for maven-bundle-plugin was in the parent pom, not the child pom eclipse was aware of.
With just the child imported, Eclipse's build problems panel showed the errors about not being able to find the maven-bundle-plugin dependency, but the "quick fix" option after right clicking on the error in the problems panel was greyed out.
Importing the parent project into eclipse caused it to pop up the prompt asking for eclipse plugin connectors to install to support the maven-bundle-plugin.

Related

How to find out about unused dependencies Maven in Intellij Idea

My project is growing but i have many unused dependencies, how to find out, which one i really need, and which one is really useless? There is a some Intellij Idea Extensions?
You can run the Maven goal dependency:analyze which lists the dependencies that are not used in your source code. Beware, though, that sometimes dependencies are necessary although they are not referenced in source code.
Add below plugin in your pom
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
</plugin>
Find maven option on Intellij, and under plugin you can trigger dependency:analyze-report

Java 11 Eclipse finds automatic module, Maven does not

I'm attempting to upgrade a 15 year old Maven multimodule project to Java 11, and the module system that was introduced in Java 9. Since the project is built using Maven, all dependencies are pretty clear. First I want to do this using the automatic module names, in order not to also introduce upgraded artifacts (if not absolutely required).
Eclipse is pretty helpful in this process, autocompleting the automatic module names in the module-info.java. For example:
requires dom4j;
But if I compile with Maven, I get errors about that it cannot find the modules Eclipse just autocompleted in there.
module-info.java:[29,18] module not found: dom4j
I am using Maven's compiler plugin 3.7.0 (3.8.0 gives a NullPointerException as per https://jira.apache.org/jira/browse/MCOMPILER-355) I suspect Maven is setting the jars up on the classpath instead of on the modulepath, but the compiler's plugin debug output does not log that.
How can I make Maven correctly handle those modules?
I was running into the same issue. Adding
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>
to my pom solved the problem for me...
Maven version 3.9.0 seems to be buggy and will not find the module although the dependency is using an Automatic-Module-Name. Downgrading to version 3.8.1 helps.

Unresolved plugin: 'org.apache.maven.plugins:maven-jar-plugin:2.4'

After I use IntelliJ IDEA to create a maven module, there is some problem in the Maven Projects view. And when my cursor hover on the maven project, i see this:
Project:
cn.itcast.babasport:parent:1.0-SNAPSHOT
Location:
/home/shuaidi/IdeaProjects/parent/pom.xml
Problems:
Unresolved plugin: 'org.apache.maven.plugins:maven-jar-plugin:2.4'
Unresolved plugin: 'org.apache.maven.plugins:maven-compiler-plugin:3.1'
Unresolved plugin: 'org.apache.maven.plugins:maven-surefire-plugin:2.12.4'
Unresolved plugin: 'org.apache.maven.plugins:maven-install-plugin:2.4'
Unresolved plugin: 'org.apache.maven.plugins:maven-site-plugin:3.3'
This is my first time using IntelliJ IDEA, so I do these thing with a new installed IDEA and a new installed maven, and i just create a maven module and didn't do any other thing. I don't know why these problem appearance.
I just want to create a maven module without any problem.
ps:
this is all my pom file.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.itcast.babasport</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
This is a duplicate of Maven plugins can not be found in IntelliJ. The top answers there did not work for me, so I'll describe what I did.
I just put the needed plugins into my ~/.m2/repository. There are two ways that achieve that. Either download the files manually with mvn dependency:get, or (my preferred way) make the plugins a dependency in some (whichever) pom.xml and build that project.
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<type>maven-plugin</type>
</dependency>
Now you can remove the dependencies. Then click "Reimport all Maven Projects" in Intellij (the blue circular arrows icon).
This issue seems completely harmless, but the squiggly lines are kind of infuriating, so I am glad I was able to get rid of them.
Instead of trying to install the plugin into your repository, actually delete it from your repository. It might have a corrupt or unsupported version that IJ cannot parse.
see https://stackoverflow.com/a/44883900/5093961
Change Maven home directory in Maven setting, and select supported Maven bundle version (Maven 2 or Maven 3), then apply setting. It's worked for me.
In my case same situation occurred because of different version exist in same system.
System have version 2.** and my project expect 3.** something
in such case, i use maven wrapper instead of maven to build project.
mvn clean install
instead of,
mvnw clean install
If you want this error to be gone without having to worry about all those xml files and copy pasting stuff just try the below solution
Note: This is manual way
In your InteliJ IDEA, go to search and type "Project Structure"
Search>Project Structure
or press:
Ctrl + Alt + Shift + S
Now go to Libraries under project settings
Project Settings>Libraries
Now look for red lined dependencies and click it
For example:
Click "Maven: javax:javaee-web-api:7.0"
Now look whether all three files are red lined
Example: Classes, Sources, JavaDocs
If any of the path under these names are redlined then go to that path and keep the folder open
For example: The path would look like this
Classes
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0\javaee-web-api-7.0.jar
Sources
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0\javaee-web-api-7.0-sources.jar
JavaDocs
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0\javaee-web-api-7.0-javadoc.jar
Now go to the folder as said above and keep it open
In my case its
C:\Users\shifny.m2\repository\javax\javaee-web-api\7.0
Now click this website
and search for the jar file
In my case it's:
javaee web api
Now click the link and select the version in next page
In my case it's:
7.0
Now find the "Files" row which will be between "Date" and "Repositories"
In the Files row, click View All
It will open a page like This
In that page download the missing files(classes,source,javadoc)
It will look like this
javaee-web-api-7.0.jar
javaee-web-api-7.0-sources.jar
javaee-web-api-7.0-javadoc.jar
Download all three and put it into the folder which I said you to keep open
Now open your project in inteliJ IDEA and build your project and open the "project structure" as instructed above and check it, the redlined files will have no redlines anymore.
This may seem easy but if there are more files which generates errors then you will have to do this process multiple times and download the missing files.
In that case the above solutions may help...
Check idea.log for errors related to Maven importing, it could be
a network issue with localhost
invalid VM options for Maven VM (too large heap or a typo in VM options)
Maven process failing for some other reason (like the recent Nvidia driver update has caused Java crashes).
I just solved this problem few minutes ago and this is what I figured and my solution:
The reason intellij is popping up with those errors is because the plugin files for those failed plugins in the ".m2" directory are not properly downloaded or they are broken.
This is what I did:
I went to "C:\Users\IYANU.m2\repository\org\apache\maven\plugins" folder. You will see that the name of the plugins matches the ones giving errors in IntelliJ
One after the other, in each plugin folder, I checked for the version giving error in IntelliJ then delete the version folder. Like for "maven-jar-plugin", the version in 2.4, delete the 2.4 folder in the maven-jar-plugin folder.
After deleting, go back to IntelliJ and reload your maven project. Make sure there is an internet connection. This will make IntelliJ properly download the plugin and the error won't pop up for that particular plugin again.
Repeat it for the other plugins giving error
Thank me later
This worked for me:
Download 'maven-jar-plugin:2.4.jar' from maven-repository (https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jar-plugin/2.4)
Paste the downloaded 'maven-jar-plugin:2.4.jar' in the local PC's mvn-repository ('C:\Users\[user-name].m2\repository\org\apache\maven\plugins\maven-jar-plugin\2.4' folder)
Wait for IntelliJ to pick up the change
All done!

Wro4j maven plugin - required class is missing

I'm trying to run wro4j maven plugin according to the documentation
I add the plugin to my pom.xml:
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>1.5.0</version>
</plugin>
and run the goal:
mvn wro4j:run -Dminimize=true -DtargetGroups=all
However the build fails with error:
org.apache.maven.lifecycle.LifecycleExecutionException: Internal error in the pl
ugin manager executing goal 'ro.isdc.wro4j:wro4j-maven-plugin:1.5.0:run': Unable
to load the mojo 'ro.isdc.wro4j:wro4j-maven-plugin:1.5.0:run' in the plugin 'ro
.isdc.wro4j:wro4j-maven-plugin'. A required class is missing: org/codehaus/plexu
s/util/Scanner
Do you know how to avoid this error?
Since wro4j-1.5.0, the maven 3.0 is required to run the plugin. The reason is a feature called incremental build support which depends on a library which is not available on older version of maven by default.
The issue is on your local environment.
Go to this folder on my windows machine:${user.home}/.m2/repository, then delete everything in this folder. (Well you can keep a copy.)
After deleting, run the Maven command:mvn clean install -U.
See: https://groups.google.com/forum/#!topic/wro4j/ZPSFBQ_5lI8

Maven: skip test but still fails on surefire

I dont know if this is a question or suggestion. But I am going to ask it as a question cos may be i am doing something wrong.
My problem was that I wanted to skip tests in maven build, In eclipse plugin I checked the Skip Test option in configuration when running maven. It was still failing on the Test surefire plugin as it couldn't download the version 2.4.3 (even though my previous maven project used a 2.7.2 and it was already there in my repo) So i tried with skipping tests and it still failed.
I configured my POM to use the 2.7.3 plugin of surefire which i already had and it went forward only to say Skipping Tests. Now, my confusion is that when it was already going to SKIP the test part why bother going into the download and confirming if the plugin for surefire is there or not. Just Skip it I say..
well, Is that the normal behavior of maven that when you skip something the plugin is still downloaded as if you are going to use it. Or was I doing it wrongly that made it download it.
May be because there was something new called "Effective POM" and it contained a listing of surefire plugin 2.4.2 in the plugin management area, when i imported my maven project in eclipse using the m2eclipse and i couldnt edit the Effective POM. I had not seen this before in the NetBeans when making the maven project.
In order to work i added an unnecessary surefire plugin entry in my build profile and skipped the tests there as well and added the version that I had in my repo already. I only did this so that my project can be built under eclipse as well. other wise my project works in NetBeans and simple command line without any issues.
Any comments!!
I think maven should be able to see first the SKIP part and then proceed into the usage of the plugin.
Syed..
Based on what you mentioned you didn't understand the difference between using a plugin and configuring the plugin. In this case you are using the plugin (it's in your build area or as you already figured out coming via super-pom). Furthermore you are trying to skip the tests despite the fact that maven-surefire-plugin in version 2.7.3 does not exist.
The configuration parameter skip will not execute the tests as well as not compile them. If you wan't just ignore the tests for a limited time you can use the "skipTest" parameter which in contradiction to skip will continue to compile the tests.
I would recommend to use a pluginManagement section of your project or your parent pom to define the version of the maven-surefire-plugin (which in the meantime exists in version 2.12)...
The following snippet add the pluginManagement part to a pom which controls which version of the maven-surefire plugin will be used.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
..
</build>
After you inserted that into your project pom the output effective pom should give you the version...otherwise you might need to update the project configuration first.
Compiling and running tests is part of the default lifecycle of maven. Since maven uses surefire to do run tests, it needs to download surefire. skipTests is not a maven configuration, but a surefire plugin configuration. The plugin determines that maven needs to skip tests.
As for 2.4.3 of surefire plugin, it is a valid version, but will work with 2.0.6 version of maven. Most likely you are using a newer maven, but, for some reason have the super pom of the older maven version on your system.
skipTest doesn't tell maven to skip the test lifecycle, it tells the surefire plugin not to run them. The plugin is still part of the lifecycle (it just does nothing when it's called). Hence your error.
If you want to NOT have surefire at all, you need to define your own packaging (since surefire is part of the standard jar packaging lifecycle) - which is a lot more work than just choosing a version of surefire that works for you (add a section with the right in your section).

Resources