Maven – Always download sources and javadocs - java

Is there a way I can configure maven to always download sources and javadocs? Specifying -DdownloadSources=true -DdownloadJavadocs=true everytime (which usually goes along with running mvn compile twice because I forgot the first time) becomes rather tedious.

Open your settings.xml file ~/.m2/settings.xml (create it if it doesn't exist). Add a section with the properties added. Then make sure the activeProfiles includes the new profile.
<settings>
<!-- ... other settings here ... -->
<profiles>
<profile>
<id>downloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>downloadSources</activeProfile>
</activeProfiles>
</settings>
Edit: As mentioned by Jingguo Yao, this works with Eclipse IDE only - the same can also be configured in your IDE of choice. In Elcipse via Window -> Preferences -> Maven menu, though this probably has to done at every workspace level and for fresh Eclipse installations.
Alternatively configure the maven-dependency-plugin in your pom.xml in a separate profile and run it as required - keeping it in the main build will lead to build times (needlessly elongating (not to mention space) at places like your build nodes that don't need either sources or java docs. Preferable this should configured in some org or division parent pom.xml, otherwise it has be repeated everywhere in different places

In my case the "settings.xml" solution didn't work so I use this command in order to download all the sources:
mvn dependency:sources
You also can use it with other maven commands, for example:
mvn clean install dependency:sources -Dmaven.test.skip=true
To download all documentation, use the following command:
mvn dependency:resolve -Dclassifier=javadoc

Just consolidating and prepared the single command to address source and docs download...
mvn dependency:sources dependency:resolve -Dclassifier=javadoc

Answer for people from Google
In Eclipse you can manually download javadoc and sources.
To do that, right click on the project and use
Maven -> Download JavaDoc
Maven -> Download Sources

I am using Maven 3.3.3 and cannot get the default profile to work in a user or global settings.xml file.
As a workaround, you may also add an additional build plugin to your pom.xml file.
<properties>
<maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
</properties>
<build>
<plugins>
<!-- Download Java source JARs. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

On NetBeans :
open your project explorer->Dependencies->[file.jar] rightclick->Download Javadoc

As #xecaps12 said, the simplest/efficient approach is to change your Maven settings file (~/.m2/settings.xml) but if it is a default settings for you, you can also set it like that
<profile>
<id>downloadSources</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>

In Netbeans, you can instruct Maven to check javadoc on every project open :
Tools | Options | Java icon | Maven tab | Dependencies category | Check Javadoc drop down set to Every Project Open.
Close and reopen Netbeans and you will see Maven download javadocs in the status bar.

To follow up on the answer from kevinarpe this does both sources and Javadocs:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<goals>
<goal>sources</goal>
<goal>resolve</goal>
</goals>
</execution>
</executions>
<configuration>
<classifier>javadoc</classifier>
</configuration>
</plugin>
</plugins>
</build>

I think it can be done per plugin. See this chapter from the Maven book.
You might be able to configure the dependency plugin to download sources (even though I haven't tried it myself :-).

Simply modify file mvn (or mvn.cmd if in windows) and add whatever command line switches you need (as mentioned by other answers). If you don't want to modify the install files (which I'd recommend), create a mymvn (or mymvn.cmd) wrapper that invokes the regular mvn with the parameters.

Not sure, but you should be able to do something by setting a default active profile in your settings.xml
See
See http://maven.apache.org/guides/introduction/introduction-to-profiles.html

I had to use KeyStore to Download the Jars. If you have any Certificate related issues you can use this approach:
mvn clean install dependency:sources -Dmaven.test.skip=true -Djavax.net.ssl.trustStore="Path_To_Your_KeyStore"
If you want to know how to create KeyStores, this is a very good link:
Problems using Maven and SSL behind proxy

For the sources on dependency level ( pom.xml) you can add :
<classifier>sources</classifier>

For intellij users, inside the pom.xml file, right click anywhere and select Maven -> Download sources and Documentation.

Related

Cannot resolve plugin org.apache.maven.plugins:maven in IntelliJ [duplicate]

After updating IntelliJ from version 12 to 13, the following Maven-related plugins cannot be resolved:
org.apache.maven.plugins:maven-clean-plugin:2.4.1
org.apache.maven.plugins:maven-deploy-plugin
org.apache.maven.plugins:maven-install-plugin
org.apache.maven.plugins:maven-site-plugin
When using IntelliJ 12, these were not in the plugins list. Somehow they've been added after the update and now IntelliJ complains they cannot be found. Where can I remove these plugins from the list OR resolve the problem by installing them?
I can run maven goals clean and compile without problem, but the profile/plugins appear red with warnings in the IDE.
EDIT after 8 years: Please also have a look at all other good answers here. The accepted answer is a common solution but might not work for you or for your IDE version
For newer versions of IntelliJ, enable the use plugin registry option within the Maven settings as follows:
Click File πŸ‘’ Settings.
Expand Build, Execution, Deployment πŸ‘’ Build Tools πŸ‘’ Maven.
Check Use plugin registry.
Click OK or Apply.
For IntelliJ 14.0.1, open the preferences---not settings---to find the plugin registry option:
Click File πŸ‘’ Preferences.
Regardless of version, also invalidate the caches:
Click File πŸ‘’ Invalidate Caches / Restart.
Click Invalidate and Restart.
When IntelliJ starts again the problem should be vanquished.
Run a Force re-import from the maven tool window. If that does not work, Invalidate your caches (File > Invalidate caches) and restart. Wait for IDEA to re-index the project.
I had this problem for years with the maven-deploy plugin, and the error showed up even though I was not directly including the plugin in my POM. As a work-around I had to force include the plugin with a version into my POMs plugin section just to remove the red-squiggly.
After trying every solution on Stack Overflow, I found the problem: Looking into my .m2/repository/org/apache/maven/plugins/maven-deploy-plugin directory there was a version 'X.Y' along with '2.8.2' et al. So I deleted the entire maven-deploy-plugin directory, and then re-imported my Maven project.
So it seems the issue is an IntelliJ bug in parsing the repository. I would not not remove the entire repository though, just the plugins that report an error.
None of the other answers worked for me. The solution that worked for me was to download the missing artifact manually via cmd:
mvn dependency:get -DrepoUrl=http://repo.maven.apache.org/maven2/ -Dartifact=ro.isdc.wro4j:wro4j-maven-plugin:1.8.0
After this change need to let know the Idea about new available artifacts. This can be done in "Settings > Maven > Repositories", select there your "Local" and simply click "Update".
Edit: the -DrepoUrl seems to be deprecated. -DremoteRepositories should be used instead. Source: Apache Maven Dependency Plugin – dependency:get.
The red with warnings maven-site-plugin resolved after the build site Lifecycle:
My IntelliJ version is Community 2017.2.4
SOLVED !!!
This is how I fixed the issue...
Tried one of the answers which include 'could solve it by enabling "use plugin registry" '. Did enable that but no luck.
Tried again one of the answers in the thread which says 'If that does not work, Invalidate your caches (File > Invalidate caches) and restart.' Did that but again no luck.
Tried These options ..
Go to Settings --> Maven --> Importing and made sure the following was selected
Import Maven projects automatically
Create IDEA modules for aggregator projects Keep source...
Exclude build dir...
Use Maven output...
Generated souces folders: "detect automatically"
Phase to be...: "process-resources"
Automatically download: "sources" & "documentation"
Use Maven3 to import
project VM options for importer: -Xmx512m
But again no success.
Now lets say I had 10 such plugins which didn't get resolve and among them the
first was 'org.apache.maven.plugins:maven-site-plugin'
I went to '.m2/repository/org/apache/maven/plugins/' and deleted the directory
'maven-site-plugin' and did a maven reimport again. Guess what, particular
missing plugin got dowloaded. And I just followed similar steps for other
missing plugins and all got resolved.
I had the same issue. I added the plugins into my pom.xml dependencies and it works for me.
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<type>maven-plugin</type>
</dependency>
<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>
I tried the other answers, but none of them solved this problem for me.
The problem disappeared when I explicitly added the groupId like this:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
Once the color of the version number changed from red to black and the problem disappeared from the Problems tab the groupId can be removed again from the problematic plugin, the error does not show up again and the version number even shows up as suggestion for version.
I am using IntelliJ Ultimate 2018.2.6 and found out, that the feature Reimport All Maven Project does not use the JDK, which is set in the Settings: Build, Execution, Deployment | Build Tools | Maven | Runner.
Instead it uses it's own JRE in IntelliJ_HOME/jre64/ by default. You can configure the JDK for the Importer in Build, Execution, Deployment | Build Tools | Maven | Importing.
In my specific problem, an SSL certificate was missing in the JREs keystore. Unfortunately IDEA only logs this issue in it's own logfile. A little red box to inform about the RuntimeException had been really nice...
I had the same error and was able to get rid of it by deleting my old Maven settings file. Then I updated the Maven plugins manually using the mvn command:
mv ~/.m2/settings.xml ~/.m2/settings.xml.old
mvn -up
Finally I ran the "Reimport All Maven Projects" button in the Maven Project tab in IntelliJ. The errors vanished in my case.
None of the other solutions worked for me.
My solution:
Maven Settings -> Repositories -> select Local Repository in the list, Update
Worked like a charm!
This did the trick for me...delete all folders and files under 'C:\Users[Windows User Account].m2\repository'.
Finally ran 'Reimport All Maven Projects' in the Maven Project tab in IntelliJ.
Remove your local Maven unknown plugin and reimport all maven projects. This will fix this issue.
You can find it under View > Tool Windows > Maven :
For me it was as simple as giving the plugin a version:
<version>3.3.0</version>
The full plugin code sample is given below:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
I was recently faced with the same issue. None of the other solutions resolved the red error lines.
What I did was run the actual targets in question (deploy, site). I could see those dependencies then being fetched.
After that, a reimport did the trick.
If an artifact is not resolvable.
Go in the directory of your .m2/repository
and check that you DON'T have that kind of file :
build-helper-maven-plugin-1.10.pom.lastUpdated
If you don't have any artefact in the folder, just delete it, and try again to re-import in IntelliJ.
the content of those files is like :
#NOTE: This is an Another internal implementation file, its format can be changed without prior notice.
#Fri Mar 10 10:36:12 CET 2017
#default-central-https\://repo.maven.apache.org/maven2/.lastUpdated=1489138572430
https\://repo.maven.apache.org/maven2/.error=Could not transfer artifact org.codehaus.mojo\:build-helper-maven-plugin\:pom\:1.10 from/to central (https\://repo.maven.apache.org/maven2)\: connect timed out
Without the *.lastUpdated file, IntelliJ (or Eclipse by the way) is enabled to reload what is missing.
I could solve this problem by changing "Maven home directory" from "Bundled (Maven 3) to "/usr/local/Cellar/maven/3.2.5/libexec" in the maven settings of IntelliJ (14.1.2).
Uncheck the "Work offline" checkbox in Maven settings.
Here is what I tried to fix the issue and it worked:
Manually deleted the existing plugin from the .m2 repo
Enabled "use plugin registry" in IntelliJ
Invalidated the cache and restarted IntelliJ
Reimported the maven project in IntelliJ
After following above steps, the issue was fixed. Hopefully this helps you as well.
For me which worked is putting the repository which contained the plugin under pluginRepository tags. Example,
<pluginRepositories>
<pluginRepository>
<id>pcentral</id>
<name>pcentral</name>
<url>https://repo1.maven.org/maven2</url>
</pluginRepository>
</pluginRepositories>
Enabling "use plugin registry" and Restart project after invalidate cash solved my problem
to Enabling "use plugin registry" >>> (intelij) File > Setting > Maven > enable the option from the option list of maven
To invalidate cash >>> file > invalidate cash
That's it...
This worked for me
Go to Settings --> Maven --> Importing --> JDK for importer -->
use "Use Project JDK" option instead of a custom JDK set previously.
Re-build/re-import all the dependencies.
This worked for me:
Close IDEA
Delete "*.iml" and ".idea" -directories(present in the root folder of project)
Run "mvn clean install" from the command-line
Re-import your project into IDEA
After re-importing the entire project, installation of dependencies will start which will take some minutes to complete depending upon your internet connection.
My case:
maven-javadoc-plugin with version 3.2.0 is displayed red in IntelliJ.
Plugin is present in my local maven repo.
Re-imported maven million times.
Ran mvn clean install from the command line N times.
All my maven settings in IntelliJ are correct.
Tried to switch between Bundled and non-bundled Maven.
Tried do delete the whole maven repo and to delete only the plugin from it.
Nothing of the above worked.
The only thing that almost always helps with modern IntelliJ IDEA versions is "Invalidate caches / Restart". It helped this time as well. maven-javadoc-plugin is not red anymore, and I can click on it and to to the source pom file of the plugin.
Recently I faced the same issue.
All tips doesn't work in my cause.
But I fix it.
Go to Intellij idea setting, find Maven, and in it you need to open Repository tab and update maven and local repos. That's all.
If you have red squiggles underneath the project in the Maven plugin, try clicking the "Reimport All Maven Projects" button (looks like a refresh symbol).
Check the plugins which cannot be found (maven-site-plugin,maven-resources-plugin)
go to '.m2/repository/org/apache/maven/plugins/'
delete the directory rm -rf plugin-directory-name (eg: rm -rf maven-site-plugin)
exit project from intellij
import project again
Do a Maven reimport
Explanation: when you do a maven reimport, it will download all the missing plugins again.
Happy Coding
I use the community edition packaged as snap on Ubuntu 18.04.
I experience that issue each time there a IntelliJ release.
In that scenario, my working solution is to invoke the invalidate cache and restart from the file menΓΉ flagging the indexes removal too.
June/2021:
No Delete, No Reimport.
What I did is, I was going to :
C:\Users\dell\.m2\repository\org\apache\maven\plugins
Then double Click on every Plugin Folders, And see what version it is downloaded.
Then I came back to pom file, and according to downloaded version, I carefully changes those versions in <version>....</version> Tags. Then refresh.
And That way, All red marks are gone, Even gone those Yellow Marks.
All Clean.
Here is my full pom file for further notice. The Project is JavaFx+Maven with Shade :
<?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>main.java.sample</groupId>
<artifactId>ThreeColumnTable</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>15.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>15.0.1</version>
</dependency>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>resources</goal>
<goal>testResources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>src/main/generated-groovy-stubs</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>org.example.App</mainClass>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version>
<configuration>
<mainClass>org.example.App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>project-classifier</shadedClassifierName>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.example.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Goto IntelliJ -> Preferences -> Plugin
Search for maven, you will see
1. Maven Integration
2. Maven Integration Extension.
Select the Maven Integration option and restart your Intellij

How to make Maven Javadoc Plugin work with any Java version

I'm using Maven Javadoc Plugin like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
I have multiple JDK versions installed and want to be able to build a project with any of them. The above configuration works fine with Java 8, but it fails with Java 11 with the following error
Failed to execute goal
org.apache.maven.plugins:maven-javadoc-plugin:3.1.1:jar
(attach-javadocs) on project ...: MavenReportException: Error while
generating Javadoc: Unable to find javadoc command: The environment
variable JAVA_HOME is not correctly set.
The obvious solution is to set JAVA_HOME. But as I mentioned, I have multiple versions of JDK, so reconfiguring JAVA_HOME every time I want to use another version wouldn't be convenient at all.
Another solution (from Unable to find javadoc command - maven) is to add the following configuration to the plugin:
<configuration>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
This makes it work with Java 11, but breaks Java 8 because the javadoc location is ${java.home}/../bin/javadoc in that case.
Ideally I always want to use javadoc from the directory where the java executable that Maven uses is, but I haven't found a way to do it with Maven Javadoc Plugin.
Maven profiles may be able to help.
Add something like this to your POM.
<profiles>
<profile>
<id>jdk-8-config</id>
<activation>
<jdk>1.8</jdk>
</activation>
<properties>
<javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable>
</properties>
</profile>
<profile>
<id>jdk-11-config</id>
<activation>
<jdk>11</jdk>
</activation>
<properties>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</properties>
</profile>
</profiles>
JDK ranges are also possible, read more on those in the linked doc.
Maven will pick up the version of Java being used to run itself, activate the correct profile, and define the property correct.
A caveat - typically we build with JAVA_HOME set, or via Jenkins which can be configured to define JAVA_HOME per job. This approach works well in those cases.
You could also investigate Maven toolchains. I have no experience with those, other than reading they help make it easier to define tool locations on various machines.

Is there a Maven plugin that runs a non-fat jar?

Imagine a normal java maven project with a Main class that produces the artifact project-a.jar. This project has a dependency on project-b.jar.
Is there a Maven plugin that allows to run that jar by a command like that?
mvn run-plugin:run org.mygroup:project-a:3.1 <args>
The plugin would resolve the runtime dependencies (using META-INF/maven/(...)/pom.xml), install the project and its dependencies to the local maven repository (if not already there), construct the classpath and invoke
java -cp (...)/project-a-3.1.jar;(...)/project-b-2.1.jar org.mygroup.Main <args>
I know that the usual way is to build an executable (fat) jar that contains the dependencies, but that's not what I am asking for.
Actually, it is not even necesary to read the pom from the jar, because maven can download it from the repositories given the coordinates.
Why this question is different to the Maven Run Project question:
I do not want to start from having the project's source already checked out. So the usual use of the exec plugin is not applicable. The OP of the Maven Run Project question obviously assumed the presence of a source code project folder. Her purpose was testing and she accepted an answer that clearly needs a project. The wording of both questions is correct, too. There is a difference between the words "project" and "jar" and their actual meaning in their respective contexts is quite different.
You can use the appassembler-maven-plugin plugin, it creates a shell script that has the dependencies in the classpath for you. Heres an example config
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
<configuration>
<extraJvmArguments>-Xms256m -Xmx1536m</extraJvmArguments>
<programs>
<program>
<mainClass>com.package.MyMainClass</mainClass>
<name>TestFormattingUtils</name>
</program>
</programs>
</configuration>
</plugin>
You can find the output script in .../target/appassembler/bin You can manually inspect the script and you'll see that its doing the type of command you wanted where it adds the jars to classpath via the command line. ie java -jar (...)/project-a-3.1.jar -cp (...)/project-b-2.1.jar <args>
I'm not a fan of jars-in-jar either, but I do maintain various tools with lots of dependencies. So, at one point, I decided to write an executable AppBoot jar which puts all the jars from a lib-subdirectory in a class-loader and then calls the main-method of the desired (executable) jar. This question prompted me to investigate if the exec-maven-plugin could do something similar, and it can.
The exec-maven-plugin does not require a "Java project" directory, but a pom.xml in a directory is required. The pom.xml I used is shown below, note that it can be placed in any (empty) directory and the application can be started by opening a shell/prompt in that directory and executing mvn exec:exec. Use mvn -X exec:exec to review the classpath used by the exec-maven-plugin.
<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>com.descartes</groupId>
<artifactId>exec-embed-demo</artifactId>
<version>1.2.2-SNAPSHOT</version>
<packaging>pom</packaging>
<!-- Start the demo using Maven repository artifacts, execute with "mvn exec:exec" -->
<properties>
<demo.version>1.2.1.GH</demo.version>
<mainclass>com.descartes.basicjsp.embed.demo.Launch</mainclass>
<appname>${project.artifactId}</appname>
<homedir>${project.basedir}/</homedir>
</properties>
<dependencies>
<dependency>
<!-- exec-maven-plugin will get all required (runtime) jar-files from this dependency. -->
<groupId>com.descartes</groupId>
<artifactId>basic-jsp-embed-demo</artifactId>
<version>${demo.version}</version>
</dependency>
</dependencies>
<build>
<!-- The "outputDirectory" is added to the classpath by the exec-maven-plugin. -->
<!-- Add this pom's directory to the classpath instead of "./target/classes". -->
<!-- The directory should contain "logback.xml" to prevent a million lines of debug output from Tomcat. -->
<outputDirectory>${homedir}</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<!-- mvn exec:exec configuration -->
<!-- Embedded Tomcat will not stop with "ctrl-c" -->
<!-- Use http://localhost:8080/shutdown instead -->
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dapp.name=${appname}</argument>
<argument>-Dapp.home.dir=${homedir}</argument>
<argument>-Dapp.conf.dir=${homedir}</argument>
<argument>-cp</argument>
<classpath/>
<argument>${mainclass}</argument>
</arguments>
</configuration>
<!-- mvn exec:java configuration -->
<!-- "ctrl-c" stops Tomcat but embedded Tomcat fails to start properly, probably a classloader issue. -->
<!--
<configuration>
<mainClass>${mainclass}</mainClass>
<systemProperties>
<systemProperty>
<key>app.name</key>
<value>${appname}</value>
</systemProperty>
<systemProperty>
<key>app.home.dir</key>
<value>${homedir}/</value>
</systemProperty>
<systemProperty>
<key>app.conf.dir</key>
<value>${homedir}/</value>
</systemProperty>
</systemProperties>
</configuration>
-->
</plugin>
</plugins>
</build>
</project>
AppBoot is part of the basic-jsp-embed project that uses embedded Tomcat and that project can be found here (to install, download the latest release, unpack the zip-file and run "mvn install" in the root directory of the multi-module project).
On a side-note: managing a jar-set is tricky, use tools like jHades to verify you will not run into trouble with multiple versions of the same class in different jar-files.
You are looking for the maven exec plugin.
mvn exec:java -Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"]
would run your program
Maven can not do what you want, simply because it has no way to resolve the dependencies of project A once it has been built into a final jar.
Maven does not magically download libraries from the Internet: what makes it work are the definition of repositories inside the pom.xml. Without pom.xml, like you seem to suggest, how would it know where to download libraries from? Maven is not a downloading tool, it is a project management tool and what you have is no longer a project but a final library.
Since you have control over project A, you should really rely on Maven conventions and either build a fat jar or an assembly (with maven-assembly-plugin).
By the way, the pom.xml file located under META-INF is not guaranteed to exist, and, in fact, it is not there if you look at Spring artifacts. Take a look at Maven Archiver documentation: the presence of this pom file is controlled by the addMavenDescriptor boolean attribute. Set this attribute to false and your main artifact will not have this pom file.

Maven plugins can not be found in IntelliJ

After updating IntelliJ from version 12 to 13, the following Maven-related plugins cannot be resolved:
org.apache.maven.plugins:maven-clean-plugin:2.4.1
org.apache.maven.plugins:maven-deploy-plugin
org.apache.maven.plugins:maven-install-plugin
org.apache.maven.plugins:maven-site-plugin
When using IntelliJ 12, these were not in the plugins list. Somehow they've been added after the update and now IntelliJ complains they cannot be found. Where can I remove these plugins from the list OR resolve the problem by installing them?
I can run maven goals clean and compile without problem, but the profile/plugins appear red with warnings in the IDE.
EDIT after 8 years: Please also have a look at all other good answers here. The accepted answer is a common solution but might not work for you or for your IDE version
For newer versions of IntelliJ, enable the use plugin registry option within the Maven settings as follows:
Click File πŸ‘’ Settings.
Expand Build, Execution, Deployment πŸ‘’ Build Tools πŸ‘’ Maven.
Check Use plugin registry.
Click OK or Apply.
For IntelliJ 14.0.1, open the preferences---not settings---to find the plugin registry option:
Click File πŸ‘’ Preferences.
Regardless of version, also invalidate the caches:
Click File πŸ‘’ Invalidate Caches / Restart.
Click Invalidate and Restart.
When IntelliJ starts again the problem should be vanquished.
Run a Force re-import from the maven tool window. If that does not work, Invalidate your caches (File > Invalidate caches) and restart. Wait for IDEA to re-index the project.
I had this problem for years with the maven-deploy plugin, and the error showed up even though I was not directly including the plugin in my POM. As a work-around I had to force include the plugin with a version into my POMs plugin section just to remove the red-squiggly.
After trying every solution on Stack Overflow, I found the problem: Looking into my .m2/repository/org/apache/maven/plugins/maven-deploy-plugin directory there was a version 'X.Y' along with '2.8.2' et al. So I deleted the entire maven-deploy-plugin directory, and then re-imported my Maven project.
So it seems the issue is an IntelliJ bug in parsing the repository. I would not not remove the entire repository though, just the plugins that report an error.
None of the other answers worked for me. The solution that worked for me was to download the missing artifact manually via cmd:
mvn dependency:get -DrepoUrl=http://repo.maven.apache.org/maven2/ -Dartifact=ro.isdc.wro4j:wro4j-maven-plugin:1.8.0
After this change need to let know the Idea about new available artifacts. This can be done in "Settings > Maven > Repositories", select there your "Local" and simply click "Update".
Edit: the -DrepoUrl seems to be deprecated. -DremoteRepositories should be used instead. Source: Apache Maven Dependency Plugin – dependency:get.
The red with warnings maven-site-plugin resolved after the build site Lifecycle:
My IntelliJ version is Community 2017.2.4
SOLVED !!!
This is how I fixed the issue...
Tried one of the answers which include 'could solve it by enabling "use plugin registry" '. Did enable that but no luck.
Tried again one of the answers in the thread which says 'If that does not work, Invalidate your caches (File > Invalidate caches) and restart.' Did that but again no luck.
Tried These options ..
Go to Settings --> Maven --> Importing and made sure the following was selected
Import Maven projects automatically
Create IDEA modules for aggregator projects Keep source...
Exclude build dir...
Use Maven output...
Generated souces folders: "detect automatically"
Phase to be...: "process-resources"
Automatically download: "sources" & "documentation"
Use Maven3 to import
project VM options for importer: -Xmx512m
But again no success.
Now lets say I had 10 such plugins which didn't get resolve and among them the
first was 'org.apache.maven.plugins:maven-site-plugin'
I went to '.m2/repository/org/apache/maven/plugins/' and deleted the directory
'maven-site-plugin' and did a maven reimport again. Guess what, particular
missing plugin got dowloaded. And I just followed similar steps for other
missing plugins and all got resolved.
I had the same issue. I added the plugins into my pom.xml dependencies and it works for me.
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<type>maven-plugin</type>
</dependency>
<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>
I tried the other answers, but none of them solved this problem for me.
The problem disappeared when I explicitly added the groupId like this:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
Once the color of the version number changed from red to black and the problem disappeared from the Problems tab the groupId can be removed again from the problematic plugin, the error does not show up again and the version number even shows up as suggestion for version.
I am using IntelliJ Ultimate 2018.2.6 and found out, that the feature Reimport All Maven Project does not use the JDK, which is set in the Settings: Build, Execution, Deployment | Build Tools | Maven | Runner.
Instead it uses it's own JRE in IntelliJ_HOME/jre64/ by default. You can configure the JDK for the Importer in Build, Execution, Deployment | Build Tools | Maven | Importing.
In my specific problem, an SSL certificate was missing in the JREs keystore. Unfortunately IDEA only logs this issue in it's own logfile. A little red box to inform about the RuntimeException had been really nice...
I had the same error and was able to get rid of it by deleting my old Maven settings file. Then I updated the Maven plugins manually using the mvn command:
mv ~/.m2/settings.xml ~/.m2/settings.xml.old
mvn -up
Finally I ran the "Reimport All Maven Projects" button in the Maven Project tab in IntelliJ. The errors vanished in my case.
None of the other solutions worked for me.
My solution:
Maven Settings -> Repositories -> select Local Repository in the list, Update
Worked like a charm!
This did the trick for me...delete all folders and files under 'C:\Users[Windows User Account].m2\repository'.
Finally ran 'Reimport All Maven Projects' in the Maven Project tab in IntelliJ.
Remove your local Maven unknown plugin and reimport all maven projects. This will fix this issue.
You can find it under View > Tool Windows > Maven :
For me it was as simple as giving the plugin a version:
<version>3.3.0</version>
The full plugin code sample is given below:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
I was recently faced with the same issue. None of the other solutions resolved the red error lines.
What I did was run the actual targets in question (deploy, site). I could see those dependencies then being fetched.
After that, a reimport did the trick.
If an artifact is not resolvable.
Go in the directory of your .m2/repository
and check that you DON'T have that kind of file :
build-helper-maven-plugin-1.10.pom.lastUpdated
If you don't have any artefact in the folder, just delete it, and try again to re-import in IntelliJ.
the content of those files is like :
#NOTE: This is an Another internal implementation file, its format can be changed without prior notice.
#Fri Mar 10 10:36:12 CET 2017
#default-central-https\://repo.maven.apache.org/maven2/.lastUpdated=1489138572430
https\://repo.maven.apache.org/maven2/.error=Could not transfer artifact org.codehaus.mojo\:build-helper-maven-plugin\:pom\:1.10 from/to central (https\://repo.maven.apache.org/maven2)\: connect timed out
Without the *.lastUpdated file, IntelliJ (or Eclipse by the way) is enabled to reload what is missing.
I could solve this problem by changing "Maven home directory" from "Bundled (Maven 3) to "/usr/local/Cellar/maven/3.2.5/libexec" in the maven settings of IntelliJ (14.1.2).
Uncheck the "Work offline" checkbox in Maven settings.
Here is what I tried to fix the issue and it worked:
Manually deleted the existing plugin from the .m2 repo
Enabled "use plugin registry" in IntelliJ
Invalidated the cache and restarted IntelliJ
Reimported the maven project in IntelliJ
After following above steps, the issue was fixed. Hopefully this helps you as well.
For me which worked is putting the repository which contained the plugin under pluginRepository tags. Example,
<pluginRepositories>
<pluginRepository>
<id>pcentral</id>
<name>pcentral</name>
<url>https://repo1.maven.org/maven2</url>
</pluginRepository>
</pluginRepositories>
Enabling "use plugin registry" and Restart project after invalidate cash solved my problem
to Enabling "use plugin registry" >>> (intelij) File > Setting > Maven > enable the option from the option list of maven
To invalidate cash >>> file > invalidate cash
That's it...
This worked for me
Go to Settings --> Maven --> Importing --> JDK for importer -->
use "Use Project JDK" option instead of a custom JDK set previously.
Re-build/re-import all the dependencies.
This worked for me:
Close IDEA
Delete "*.iml" and ".idea" -directories(present in the root folder of project)
Run "mvn clean install" from the command-line
Re-import your project into IDEA
After re-importing the entire project, installation of dependencies will start which will take some minutes to complete depending upon your internet connection.
My case:
maven-javadoc-plugin with version 3.2.0 is displayed red in IntelliJ.
Plugin is present in my local maven repo.
Re-imported maven million times.
Ran mvn clean install from the command line N times.
All my maven settings in IntelliJ are correct.
Tried to switch between Bundled and non-bundled Maven.
Tried do delete the whole maven repo and to delete only the plugin from it.
Nothing of the above worked.
The only thing that almost always helps with modern IntelliJ IDEA versions is "Invalidate caches / Restart". It helped this time as well. maven-javadoc-plugin is not red anymore, and I can click on it and to to the source pom file of the plugin.
Recently I faced the same issue.
All tips doesn't work in my cause.
But I fix it.
Go to Intellij idea setting, find Maven, and in it you need to open Repository tab and update maven and local repos. That's all.
If you have red squiggles underneath the project in the Maven plugin, try clicking the "Reimport All Maven Projects" button (looks like a refresh symbol).
Check the plugins which cannot be found (maven-site-plugin,maven-resources-plugin)
go to '.m2/repository/org/apache/maven/plugins/'
delete the directory rm -rf plugin-directory-name (eg: rm -rf maven-site-plugin)
exit project from intellij
import project again
Do a Maven reimport
Explanation: when you do a maven reimport, it will download all the missing plugins again.
Happy Coding
I use the community edition packaged as snap on Ubuntu 18.04.
I experience that issue each time there a IntelliJ release.
In that scenario, my working solution is to invoke the invalidate cache and restart from the file menΓΉ flagging the indexes removal too.
June/2021:
No Delete, No Reimport.
What I did is, I was going to :
C:\Users\dell\.m2\repository\org\apache\maven\plugins
Then double Click on every Plugin Folders, And see what version it is downloaded.
Then I came back to pom file, and according to downloaded version, I carefully changes those versions in <version>....</version> Tags. Then refresh.
And That way, All red marks are gone, Even gone those Yellow Marks.
All Clean.
Here is my full pom file for further notice. The Project is JavaFx+Maven with Shade :
<?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>main.java.sample</groupId>
<artifactId>ThreeColumnTable</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>15.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>15.0.1</version>
</dependency>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>resources</goal>
<goal>testResources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>src/main/generated-groovy-stubs</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>org.example.App</mainClass>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version>
<configuration>
<mainClass>org.example.App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>project-classifier</shadedClassifierName>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.example.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Goto IntelliJ -> Preferences -> Plugin
Search for maven, you will see
1. Maven Integration
2. Maven Integration Extension.
Select the Maven Integration option and restart your Intellij

Disable maven build number plugin

Currently we are working on the big maven project that has about 100 modules, some of them have submodules as well.
Some of modules use Maven Build Number plugin. The project is hosted under subversion.
Recently we started to use git locally in our development team.
After cloning subversion repo and trying to build the Project, we received following well known error:
The svn command failed.
Command output:
svn: β€˜.’ is not a working copy
Unfortunately in our case it is not an option to create a new profile or just remove plugin definition from POM (this will follow to messing up hundreds of POM files).
I found the following article http://abstractionextraction.wordpress.com/2012/09/27/git-svn-vs-maven-build-number-plugin/ but honestly, it's not something that I would really like to do...
Is there any smart way to disable this plugin. Like command-line parameter?
I think you may skip failure on obtain revision without change project pom.xml - buildnumber-maven-plugin has option revisionOnScmFailure which you may use like:
mvn -Dmaven.buildNumber.revisionOnScmFailure=no-scm package
In that case value no-scm will be used if scm call was unsuccessful. Off course you may change it and provide any other string.
Per the mojo documentation, you could use the revisionOnScmFailure property.
However, it doesn't have a command line option. You'll have to modify those pom.xml files.
See "Defining Parameters Within a Mojo" in the Maven Java Plugin Development Guide
One approach would be to use a property in your pom to specify the execution phase of the build number plugin, as shown below.
<project>
..
<properties>
<buildnumber.plugin.phase>validate</buildnumber.plugin.phase>
..
</properties>
..
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>${buildnumber.plugin.phase}</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
..
</configuration>
</plugin>
</plugins>
..
</project>
Then provide the property on the command line to disable the plugin, as shown in the following example.
mvn install -Dbuildnumber.plugin.phase=none

Categories

Resources