I have an EAR project which has an EJB module included, now my question is why I have to include the third party dependency both in EAR pom and as well as in EJB pom?
Can't I put the dependency in only EJB POM???
you don't need to add third party dependency on EAR POM ! you must add these depencencies only on EJB POM and add EJB as a depencency on EAR POM.and finally these dependencies goes to lib folder of EAR module.
Related
According to the concept of transitive dependency, if a project, say it A has dependency on X jar and is included in A's pom.xml. Now my second project, say it B has dependency on both project A and X jar. So now in my B's pom.xml I'll add only project A in its dependency, as X jar is served by A by concept of transitive dependency.
But instead of X jar if I have an Uber(shaded) jar then when I build project B, it fails saying packages included in Uber jar are missing. Means the concept is failing.
Please help me understand if I'm missing any concept or miss understanding transitive dependency.
The com.adobe.aem:uber-jar dependency typically has the <scope> set provided. This also the case for most AEM maven dependencies.
provided dependencies are not transitive, please read the maven doc on transitive dependencies: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
in the maven doc link above, please read the "Dependency Scope" section.
From the doc:
provided:
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
I have project A which contains following dependency:
<dependency>
<groupId>vo.cjm.modules.shared</groupId>
<artifactId>basic</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
In the pom of this dependency I have a plugin configured. However, this plugin is never executed when installing the project in the maven local repo. When moving the plugin to the pom of project A, it is executed.
In contrast to parent-child maven projects where plugins are inherited, here I find myself in the situation where only dependencies are inherited. Is it true that when using pom type, only dependencies are inherited and no plugins? If yes, how can I achieve to inherit plugins in maven without parent-child structure?
What I also tried, was using a parent project. In this project I define the child module, project A. In project A, I reference the parent project. When doing this, maven generates 'duplicate version' errors/warnings. The only way to eliminate this behavior is removing the version of project A. Now, projects A version is inherited from the parent project. I want to be able to manage the version of project A independently, so this is not an option.
I also tried to use a parent project, and define a module (project A) in there. However, this only works with the assumption you will always call maven on the parent project. Running maven on project A, will not inherit anything that is in the parent project.
You have to distinguish the parent-child mechanism and the dependency mechanism.
When specifying a parent for a pom (thus becoming a child pom), you will inherit every dependencies and plugins declared in <dependencies> and <plugins> elements, among other things
When referencing dependencies in your pom with <dependencies>, you're telling Maven "I need this artifact (jar, pom, other) in my project, and any other dependency this artifact is also depending on", but nothing related to plugins used by this dependency. Plugins are only used when building something with Maven. Once the artifact is built and available, there is no reason to include the plugins used by this artifact when it was built - imagine if for every dependency you used, you had tons of plugins you probably don't want suddenly added to your build !
Is it true that when using pom type, only dependencies are inherited and no plugins?
Yes. When your dependency is of type pom, you're simply telling Maven to add all the dependencies of this pom to the current pom.
If yes, how can I achieve to inherit plugins in maven without parent-child structure?
To the best of my knowledge, you can't. You have to use a parent pom if you want to inherit plugins.
I'd say that dependencies are not part of the Maven project object model, so I'd say no.
We're using parent-child architectures to reuse plugins from parents.
We omit using them as Snapshots
parent with plugins +
|
+ another parent with plugins +
| |
| + child artifact uses plugins
+ child artifact uses plugins
and so on.
So parents can for example define a Java version, or they can contain profiles that child projects can use.
These are no reactor projects (no "modules"), just plain POM projects for this exact reason: To provide plugins, profiles and dependencyManagement for children.
Grails is able to configure dependencies when you specify them in the BuildConfig.groovy file. Usually when you add it there and call grails compile --refresh-dependencies it will resolve the dependency, and download to .grails/ivy-cache/..... (in my case). However, one time, after downloading the jar files, it failed to automatically add the jar to the classpath. Does anybody have any idea on how this will happen? It has worked for me before on many other Maven repository dependencies. The specific dependency I failed to add to my Grails project classpath is http://mvnrepository.com/artifact/javax.mail/mail/1.4.7
I can just manually add the lib to the classpath, but I'd rather have dependencies resolved automatically with the BuildConfig.groovy file. I also can't manually add jars into the "Grails Dependencies" library in the classpath; they can only be outside that library.
we work on grails and have many projects. But we have a situation that many of the projects use same lib jar files. The problems with this approach is management of libraries jar files. For example, If any of the library changes, we need to remove and copy that lib jar in every project. So how can I set external lib location for grails, so that a single lib location can be shared by different grails application.
Thanks
You can use Maven to deal with the Jar and then use the dependency resolution to get the Jar into the Grails apps.
For example if you uncomment the mavenCentral() line you can use a jar like the following:
dependencies {
runtime('com.googlecode.jslint4java:jslint4java-ant:2.0.0') {
}
}
When ever you need to upgrade the jar it is very easy to go and update this listing to the new version.
I have a plugin that loads a custom Ivy resolver. It uses ${basedir}
to locate the jar file containing the resolver so I can load it inside
BuildConfig (see the answer for context). That compiles the plugin, but unfortunately, when the plugin is installed in a project,basedir becomes the project directory so it can't find the jar. pluginBasedir doesn't seem to point to anything, even inside the plugin's BuildConfig.groovy.
Is there any way to figure out the plugin base directory from within a
plugin's BuildConfig.groovy?
Ultimately I just want my custom resolver (in an external jar) to work when compiling the plugin and when compiling any project the plugin is a part of. Any solution is welcome.
The best answer I could come up with was to get my jar into a public Maven repo and use #Grab. e.g.,
#Grab(group='com.noahsloan.atg',module="atg-resolver",version="1.0")
import com.noahsloan.atg.ivy.AtgModuleRepository
grails.project.dependency.resolution = {
resolver AtgModuleRepository.newResolver
From my plugin. I'd still like to know if there is a way to reference pluginBasedir from BuildConfig.