how to create new maven dependency plugin for maven project - java

I had created a maven project using java .
Now i want to create a maven dependency so that any other can use this dependency in his own sbt project and will be able to access functions of my maven project .
e.g. As we do , if we want to use akka in our sbt project , then we simply write the mvn dependency plugin( "com.typesafe.akka" %% "akka-slf4j" % "2.4.8") for akka in my sbt project . and we can access all those class and functions provided by akka .
Simillarly i want to create some plugins for my maven project .
Please guide me how should i start ?
Thanks in advance.

Once you have compiled and tested your libraries you need to install mvn install it to repository, it can be your company hosted shared repository and any public repository. You should be able configure this repository settings in your pom.xml or settings.xml file.
Once you installed your artifact in a particular repository, your co-worker or any other can access them in java or scala, as long as they have the access to this repository. Typically they will have to specify your repository in there pom xml.

Related

Can we use github repository as an artifact while creating maven project?

I've implemented a maven library and published it to GitHub. Now I wanted to use this repository as an archetype to create another maven project (without maven central repo) like below
When I tried this it's giving the below error
Is there any way to do this?
You'll need to have a git repo which defines 'archetype' project and then package and install it's generated artifact into the github hosted artifact repository.
See this maven guide to define the archrtype
https://maven.apache.org/guides/mini/guide-creating-archetypes.html
And use github actions to publish the artifact.

Maven connection to IDE

I am using Maven to use Postrgres SQL driver. Besides I am using InteliJ IDEA Ultimatre Edition, and, as I understood, Maven is included in Ultimate version initially. Correct me - all I need, is to set dependencies, and connect PostrgeSQL to Java. I am not oblige to Download Maven (except required Dependecie of course, I mean Maven as framework)? Thanks a lot!
When you are creating a new project, choose Maven. After the project is created, you will receive an empty Maven project structure with the pom.xml and a script mvnw of Maven Wrapper, which you can use (instead of mvn) to build your app.
Just add dependencies to the pom.xml and build.
The Maven Wrapper will do the work for you - download Maven into the project subdirectory and use it.

How add alfresco extension to project which is build on alfresco maven sdk?

Suppos that repo and share module were generated from maven alfresco archetype as described here. And now it needed to install one of alvex addons. It is clear that jars/amp can be build from sources, but what to do with this? Where to put they in generated maven project to get them installed in alfresco when mvn integration-test -Pamp-to-war is executed?
That tutorial assumes two separate maven projects created using the repo archetype and the share archetype, respectively.
If you want to be able to run integration tests with multiple AMPs you may rather use the all-in-one archetype instead.
See How to use external AMP in alfresco Maven Project

How to trigger mvn install during package of a different project?

I have a "commons" library that I install to my local repo using mvn install. That library provides common company stuff used in different, not connected projects.
So I include that library as a maven dependency. And when I run mvn package on the final projects, there have been days where I forgot that I have to explicit install the commons library to get the changes picked up during package of the implementation projects.
Is there any chance I could trigger/invoke install of a different project during package?
You will have to use Antrun maven plugin, and execute shell command using ant while running properr lifecycles of maven build.
Here you have some details on configuration
http://maven.apache.org/plugins/maven-antrun-plugin/
If repository manager or external scripting (Ant) is not an option you could tweak your project structure. You could introduce an aggregator maven project which will run modules in a predefined order:
<packaging>pom</packaging>
...
<modules>
<module>[path to commons project]/commons</module>
<module>[path to your module project]/module</module>
</modules>
So whenever you want to build your project you build this aggregator project instead.

Java to Maven project conversion related details

I am having a java project with a ant build file, using this ant file i create an ejb of the project and deploy it on the jboss server.
Now I am planning to use maven and convert this existing project which consist of nearly 28-30 jar's in its class path(jars related to ejb3, hibernate, jboss, etc).
I can easily do it using eclipse i.e right click project goto maven and click Conver to Maven.
A pom.xml is generated and the MavenClassPath Container is also added to the project.
Now I want to know how to get rid of those 28-30 jar's present in the lib folder of the project and in the classpath. i.e. I want my pom.xml handle all the dependencies.
Does Maven provide any mechanism to achieve this goal while converting the project or I have to add all of these jar dependencies one by one manually in the pom.xml file.
The intention of doing this is I want to have common maven remote repository where the jars will be stored and each developer machine will point to it through their maven project.
Thanks
I think you're after a repository manager like Nexus (I use Nexus, it seems to be the most popular http://nexus.sonatype.org/ ).
Nexus can be used as:
A proxy repository (for Maven Central, etc)
A repository for your own releases.
Nexus provides user management for your developers to release builds into the repo.
Developers will then point their Maven settings.xml file to your Nexus repository, and all their dependencies will come from here (Nexus will cache them).
I'm afraid you will have to configure the dependencies individually, but that is a good thing, because you should pay attention to what version ranges you are interested in for each dependency.
Any jars which can't be found in Maven Central, etc, you can add to your own Nexus repository .
Ofcourse there are alternatives to Nexus, but I haven't used any.
HTH
The most important thing i can recommend is to use a Maven Repository Manager (Nexus, Artifactory or Achiva or other..).
Second your pom conversion via Eclipse shows me that you are not using an up-to-date Eclipse nor an up-to-date Maven Plugin for Eclipse. The best thing would be use Eclipse-Indigo (m2e is the newest and greatest).
Furthermore you have to go through all your jar's and add them step by step to you pom (dependencies) and see if your project can be compiled. This should be checked on command line not inside Eclipse.
After you got a working pom.xml file put it into your version control and check if you can remove some of your added dependencies based on transitive dependencies. After that you can finally delete your lib folder.

Categories