jdb maven: InstallMojo source - debugging

I try to debug install::install using mvnDebug/jdb -attach 8000
I get easily to org.apache.maven.plugin.DefaultBuildPluginManager:101
and then step on mojo.execute() which leads me to:
main[1] where
[1] org.apache.maven.plugin.install.InstallMojo.execute (InstallMojo.java:76)
[2] org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:101)
...
I find the sources for InstallMojo.java from svn, but how should I know what tag to checkout?
Thanks,
Marc

Based on the given information you are using the 2.3.1 version of the maven-install-plugin you can simply read the pom file of that particular version which means search for that version in maven central. And the pom file will give you the information you need:
Excerpt:
<scm><connection>scm:svn:http://svn.apache.org/repos/asf/maven/plugins/tags/maven-install-plugin-2.3.1</connection>
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/plugins/tags/maven-install-plugin-2.3.1</developerConnection>
This gives you the exact location of the SVN Tag in the apache SVN repository and of course the correct location which you can checkout.

Related

How to get latest artifact from artifactory?

I have artifacts in JFrog.
Example:
https://test.com/artifactory/users/data-config/1.0.0/user.json
https://test.com/artifactory/users/data-config/1.0.1/user.json
https://test.com/artifactory/users/data-config/2.0.0/user.json
Is there a way I can download the latest version using curl? Like in this case it will be
https://test.com/artifactory/users/data-config/2.0.0/user.json
Considering your comment that the files are not maven based, I assume it is deployed to a generic repository and irrespective of the file type, the only way to resolve the file via direct cURL is using the following command.
curl -u<USERNAME>:<PASSWORD> -O "http://<HOSTNAME>:<PORT>/artifactory/generic-repository/<TARGET_FILE_PATH>"
So, the target path name should be given completely when it is being resolved via direct download (API). i.e., The complete target file name manually.
However, for other package types such as a maven release or a snapshot, the available options are described here.
What are a few other additional options available?
Artifact Latest Version Search Based on Layout
, Artifact Latest Version Search Based on Properties

How to add new features to OpenDayLight Karaf?

How can I add new features to ODL Oxygen SR3 (0.8.3) as a Karaf module?
For example, I downloaded the prebuilt ODL from the official page. Then I'd like to make the Toaster sample as a new module for Oxygen, it was created with command:
wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
mvn archetype:generate -DarchetypeGroupId=org.opendaylight.archetypes -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeCatalog=remote -DarchetypeVersion=1.1.0-SNAPSHOT
After compiling, it would generate built files to a local maven repository (~/.m2/repository/com/example/toaster). I copied the com/example/toaster to the Karaf default repository folder ./karaf-0.8.3/system. Then I'd like to make it available in feature:list so I can install with feature:install toaster. First I need to add it to the repo list:
./karaf-0.8.3/bin/karaf
feature:repo-add mvn:com.example.toaster/features-toaster
Unfortunately it showed an error:
Error executing command: Error resolving artifact com.example.toaster:features-toaster:jar:0.1.0-SNAPSHOT:
[Could not find artifact com.example.toaster:features-toaster:jar:0.1.0-SNAPSHOT in opendaylight-snapshot (https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/)] : mvn:com.example.toaster/features-toaster
The above command is based on this post. What's the correct way to do repo-add?
Please read the https://karaf.apache.org/manual/latest/#_artifacts_repositories_and_urls
Article.
What you need to do is basically add the repo URl that contains your toaster to the package like so:
(Example from the documentation linked above)
<bundle>http://repo1.maven.org/maven2/org/apache/servicemix/nmr/org.apache.servicemix.nmr.api/1.0.0-m2/org.apache.servicemix.nmr.api-1.0.0-m2.jar</bundle>
Repositories can also be defined using properties:
org.ops4j.pax.url.mvn.repositories : Comma separated list of remote
repository URLs that are checked in order of occurence when resolving
maven artifacts
Source: https://karaf.apache.org/manual/latest/#_maven_url_handler
After building change configuration at the end of file karaf/target/assembly/etc/org.ops4j.pax.url.mvn.cfg into
org.ops4j.pax.url.mvn.repositories= \
file:${karaf.home}/${karaf.default.repository}#id=system.repository, \
file:${karaf.data}/kar#id=kar.repository#multi, \
https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot#id=opendaylight-snapshot#snapshots, \
https://nexus.opendaylight.org/content/repositories/public#id=opendaylight-mirror
Then you can add a repository with
feature:repo-add mvn:org.opendaylight.netconf/features-restconf/1.9.0-SNAPSHOT/xml/features
where groudId: org.opendaylight.netconf, artifactId: features-restconf and version: 1.9.0-SNAPSHOT are depending on the feature you want to add. You can search at https://nexus.opendaylight.org/ with Articfact Search for them and find them in the Maven pom.

how to force maven to update local repo

I compiled a jar file in one project so it can be consumed in the 2nd one. I can see the jar file in .m2 folder. But in the 2nd project it complains about artifact not found.
I guess I have to force maven to update indices/cache something but don't know what exactly. Any tip, thanks.
Update: thanks for all good suggestions.
Turns out that the maven plugin (of IntelliJ) in the second project doesn't update its index. I use command line it compiled ok.
try using -U (aka --update-snapshots) when you run maven
And make sure the dependency definition is correct
You can also use this command on the command line:
mvn dependency:purge-local-repository clean install
If you are installing into local repository, there is no special index/cache update needed.
Make sure that:
You have installed the first artifact in your local repository properly. Simply copying the file to .m2 may not work as expected. Make sure you install it by mvn install
The dependency in 2nd project is setup correctly. Check on any typo in groupId/artifactId/version, or unmatched artifact type/classifier.
Even though this is an old question, I 've stumbled upon this issue multiple times and until now never figured out how to fix it. The update maven indices is a term coined by IntelliJ, and if it still doesn't work after you've compiled the first project, chances are that you are using 2 different maven installations.
Press CTRL+Shift+A to open up the Actions menu. Type Maven and go to Maven Settings. Check the Home Directory to use the same maven as you use via the command line
Click settings and search for "Repositories", then select the local repo and click "Update". That's all. This action meets my need.
If you are struggling with authenticating to a site, and Maven is caching the results, simply removing the meta-data about the site from the meta-data stash will force Maven to revisit the site.
gvim <local-git-repository>/commons-codec/resolver-status.properties

How to get Maven dependencies printed to a file in a readable format?

I am working on a big projects with many pom.xml files and I need to specify all the libraries that I use. This means that I need to read pom.xml files recursively and get groupId, artifactId, scope and version. I checked out mvn dependency:tree but I can't find a way to print it to a file in a readable format. I saw appendOutput but I saw no example on how to use it in cmd. I saw some solutions done in Linux but I only have access to Windows XP.
This can (at least now) be done with command line options to the dependency:tree plugin.
Try:
mvn dependency:tree -Doutput=/path/to/file
Reference: Maven Dependency Plugin Page
You only asked about "readable" format, but you can also pass the -DoutputType parameter with various options. Also note that the version I have installed, I get the following warning:
[WARNING] The parameter output is deprecated. Use outputFile instead.
So, consider trying it with -DoutputFile=/path/to/file
Also, I was unable to get the -DoutputType paramater to give me anything other than the default text, but didn't have a chance to play around with it. YMMV.
If you have multiple modules under the same repo/project and want the dependencies of all the modules in one file, so as to be able to diff b/w one build and another to see if something changed somewhere, you can do
$project_dir> mvn dependency:tree -DoutputFile=<absolute_path_to_file> -DappendOutput=true
e.g.
$project_dir> mvn dependency:tree -DoutputFile=`pwd`/mvn_dependency_tree.txt -DappendOutput=true
See other options available at https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html
Adding the
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>depends-maven-plugin</artifactId>
</plugin>
plugin produces a classes/META-INF/maven/dependencies.properties file with the project dependencies easily parseable.
Example of the output produced:
# Project dependencies generated by the Apache ServiceMix Maven Plugin
# Generated at: Mon Oct 10 17:43:00 CEST 2011
groupId = my.group.name
artifactId = my.artifact.name
version = 0.0.1-SNAPSHOT
my.group.name/my.artifact.name/version = 0.0.1-SNAPSHOT
# dependencies
junit/junit/version = 4.8
junit/junit/type = jar
junit/junit/scope = test
org.easymock/easymock/version = 2.4
org.easymock/easymock/type = jar
org.easymock/easymock/scope = test
On GNU/Linux I would just do mvn dependency:tree > myFile. However, if you're restricted to Windows only, than I would look for Windows' syntax for streaming the output of a command.
According to this site (just a top-results from Google) it seems that Windows' console also use > sign to direct the output stream to i.e. a file.
So would you mind trying this?
I have run the below command and got the file having all the maven dependency.
mvn dependency:tree -DoutputFile=temp/mvn_dependency_tree.txt
This command will create a folder named "temp" and inside this folder a file name mvn_dependency_tree.txt will be created with all the dependencies.
You can always install MinGW and MSYS and then use the Linux examples using dependency:tree in Windows
Perhaps effective-pom (in conjunction with some linux commands for saving the file) can be sufficient for your needs.

How to index a Maven repo without Nexus/Artifactory/etc?

I run my own little Maven repo for some open source. I have no dedicated server so I use a Google code repository, deploy to file system and then commit and push. Works perfect for me.
But some Maven tools are looking for a nexus-maven-repository-index.properties and the index (in GZ). I would like to generate this index to
get rid of the warning that it's not here
Maven doesn't try the repo for artefacts that are not there.
How can I do that? Is there a tool (Java main) that is able to generate an index? Also tips how to use the proper Nexus Jars with a little commandline tool are welcome.
I came across this post while I was searching for a solution to add a local repository to my Maven project using IntelliJ Idea.
Since Sonatype changed their paths and reorganized the downloads since the last post, here is an updated step-by-step tutorial to get your repository indexed for use with IntelliJ Idea:
Download the latest stand-alone indexer from here.
Extract it somewhere and go into this directory
From the console, run this command: export REPODIR=/path/to/your/local/repo/ && java org.sonatype.nexus.index.cli.NexusIndexerCli -r $REPODIR -i $REPODIR/.index -d $REPODIR/.index -n localrepo
In the directory .index within the repository directory, some files will be created including the file "nexus-maven-repository-index.gz" which is the file IntelliJ looks out for.
You can use the Maven Indexer CLI to product the index directly, but why bother hosting your own repo when OSS projects can use a hosted one for free?
http://nexus.sonatype.org/oss-repository-hosting.html
I was looking at maven indexer... but I am not sure what for is the last parameter indexDir in the method:
public RepositoryIndexer createRepositoryIndexer(String repositoryId,
File repositoryBasedir,
File indexDir)
is it like starting point in the repositoryBasedir?

Resources