Using maven to manage java dependencies in jruby rails application

I am trying to write pom.xml that will allow me to run the command locally and get all the dependencies that are in my jruby Rails application. I see two different configurations, and I'm not quite sure what to use (since I'm not a Java person)

Firstly, for many Pom, I see only the tag under the root pom.xml, which lists all the dependencies. However, this does not have any information about where they are stored, etc., so I feel that this is not what I want (I need to copy them to the lib dir rails)

The second option that I see in mvn docs is to use the maven-dependency plugin, which is more like what I'm looking for. I assume my outputDirectory will be something like lib

Therefore, I do not quite understand what the purpose of the first list of dependencies is for. All I want is mvn to copy my banks locally (and then, eventually, when my CI server is deploying). Can someone point me in the right direction?

First option

 <project> <dependencies> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.4</version> </dependency> </project> 

Second option

 <project> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <configuration> <artifactItems> <artifactItem> <groupId>[ groupId ]</groupId> <artifactId>[ artifactId ]</artifactId> <version>[ version ]</version> <type>[ packaging ]</type> <classifier> [classifier - optional] </classifier> <overWrite>[ true or false ]</overWrite> <outputDirectory>[ output directory ]</outputDirectory> <destFileName>[ filename ]</destFileName> </artifactItem> </artifactItems> <!-- other configurations here --> </configuration> </plugin> </plugins> </build> </project> 
+4
source share
1 answer

Firstly, for many Pom, I see only the tag under the root pom.xml, which lists all the dependencies. However, this does not have any information about where they are stored, etc., so I feel that this is not what I want (I need to copy them to the lib dir rails)

This is the traditional way to declare and use dependencies on a Java project. Dependencies declared under the <dependencies> element are downloaded from the "remote repository" and installed into your "local repository" (by default ~/.m2/repository ), and then the artifacts are processed. Maven projects (at least Java) do not use the local lib/ folder for their dependencies.

The second option that I see in mvn docs is to use the maven-dependency plugin, which is more like what I'm looking for. I assume my outputDirectory will look like lib

The maven dependency plugin allows you to interact with artifacts and copy / unpack them from local or remote repositories to a specified location. Thus, it can be used to get some dependencies and copy them, let's say the lib/ directory. In fact, there are several purposes for this:

  • dependency: copy takes a list of artifacts defined in the configuration plugin and copies them to the specified location, renaming them or, if necessary, depriving the version. This target can allow artifacts from remote repositories if they do not exist locally.
  • dependency: copy-dependencies displays a list of direct dependency projects and optionally transitive dependencies and copies them to the specified location, stripping version if desired. This target can also be run from the command line.

The first goal will use the setting described in the second option. The second goal will use the standard project dependencies that you described in your first version. Both approaches will work.

The problem is that I don’t know exactly what a JRuby Rails application is, what the development workflow is, how to create such an application, etc., so I don’t know exactly what you need to do, and therefore what would be The best way to implement this with Maven.

So, I searched google a bit and found this post which shows a different approach based on OS commands (using maven exec) and has full pom.xml execution of some other functions. Perhaps you should take a look at it and use it as a starting point, rather than reinventing everything. Actually this is my suggestion.

+1
source

Source: https://habr.com/ru/post/1300817/


All Articles