I have no experience with maven, so excuse me if this question is silly...
From another question (How does Grails handle plugin dependencies), I've learned that I can avoid the jar-hell in grails through maven repositories. But I now have the requirements that...
I am not allowed to use remote maven repositories
I would like to bundle the needed jars with my plugin (but low priority)
I would like to avoid the effort to install a local maven repository
I already worked with a reference to a local folder for plugin resolution. This works great.
But how do I have to structure a local folder in order to use this option:
repositories {
flatDir name:'myRepo', dirs:'/path/to/repo'
}
I mean, I could just drop the jar files to this folder, but how do I then reference those jar files? Do they have a naming schema like artifact_version.jar? Or do I have to create an XML configuration for this local repository?
Or is the effort to use a local maven repo small and maven is even already on my machine through grails?
The fact is Maven comes already with a local repository (~/.m2 on linux boxes). If you don't have access to an external repo, you just have to install your jars in the local repo, with this command
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
is 'jar' (without quotes) and group-id and artifact-id are either determined if it's 3rd-party library (go make a search on mvnrepository.com if you don't know them for a particular library) or you put there your group and artifact ids
EDIT : In fact, the naming scheme under the repository is for the library example version 1.2 from jexample.com is usually com/jexample/example/1.2/example-1.2.jar (groupId : com.jexample, artifactId : example, version : 1.0)
Related
How can I make grails download artifacts(plugins and dependencies) to my local maven repository or the grails version folder so that i can save bandwidth when create and run a new project or rather use them offline(as a version global cache maybe, instead of a project).
You may want to read the documentation regarding dependancy resolution. There is a section about Local Resolvers which should allow you to use your local maven repository.
To specify your local Maven cache (~/.m2/repository) as a repository:
BuildConfig.groovy
repositories {
mavenLocal()
}
I am modifying the hadoop source code but when I do a compile in maven it downloads from the maven repository, which is causing problems as my changes are not always be used.
How can I get maven to not download some files from the repository at all, and just use what is in the local classpath?
I am using maven 3.0.4
The best way is to give to "hadoop source code" a different SNAPSHOT version or a different artifactId and refer to it.
However, I think it is a stupid answer.
You can set local settings to offline=true. http://maven.apache.org/ref/3.0.3/maven-settings/settings.html;
or use a repository manager (sucha as Nexus) http://maven.apache.org/repository-management.html and deploy to Repository
Update these properties inside of your POM file to disable updates of your dependencies.
enabled: true or false for whether this repository is enabled for the
respective type (releases or snapshots).
updatePolicy: This element specifies how often updates should
attempt to occur. Maven will compare the local POM's timestamp
(stored in a repository's maven-metadata file) to the remote. The
choices are: always, daily (default), interval:X (where X is an
integer in minutes) or never.
POM Reference - MAVEN Site
If I want to use a plugin for Grails from Git Hub. Do I just download the zip file and make it available in my local maven repository? I'm behind a firewall which doesn't let me just resolve the dependencies.
You can get the source and run maven-install to make it available in your local maven repository, then you declare the dependency in the plugins block of the BuildConfig.groovy.
You shouldn't build from the repo source since that might include unfinished features and bugs. At the very least use source tagged for a particular release (if there are any).
If you want to download released plugins, they're available at http://repo.grails.org/grails/plugins/org/grails/plugins/
Keep in mind that running grails install-plugin /path/to/zip no longer works in 2.3, so you should stay away from that approach. Instead, you could run a local Artifactory instance that acts as a cached plugin repo - see this thread for some information to get started: http://grails.1312388.n4.nabble.com/Caching-plugins-using-artifactory-td4640164.html
The zip file which will be downloaded will be the source of the plugin. You have to extract the zip, go to the root of the plugin, and run grails maven-install (from release plugin) which would build the plugin artifact for you in you local maven repository if you have one setup.
Then you can use the plugin.
OR
You can use the plugin inline as mentioned in this answer.
Proxy setting can also be configured in grails by add proxy and set proxy.
grails add-proxy myproxy "--host=myproxy" "--port=myport" "--username=proxyuser" "--password=mypassword"
grails set-proxy myproxy
see grails docs.
if above solution doesn't work try then
create ProxySettings.groovy in C:\Documents and Settings\user-name.grails folder
add following two lines to this file and save
myproxy=["http.proxyHost":"myproxy", "http.proxyPort":"4300", "http.proxyUserName":"proxyuser", "http.proxyPassword":"mypassword"]
currentProxy="myproxy"
please check this link for more options
You can also keep plugins locally as described here
http://blog.armbruster-it.de/2011/10/project-setup-for-grails-with-customized-plugins-using-git-submodules/
git submodule add git://github.com/sarmbruster/grails-spring-security-ui.git plugins/grails-spring-security-ui
git add .gitmodules plugins/
git commit -m "added submodule"
now add plugins/grails-spring-security-ui as a inline plugin by adding to grails-app/conf/BuildConfig.groovy
grails.plugin.location.'spring-security-ui'="plugins/grails-spring-security-ui"
That's all.
More info in section "Installing Local Plugins" and "Specifying Plugin Locations" in docs:
http://grails.org/doc/latest/guide/plugins.html#12.1%20Creating%20and%20Installing%20Plug-ins
The ivy local repository is in ~/.ivy2, and I'd like to use it as my local maven respoitory. Is there any easy way like setting to do it ?
I suspect what you're trying to do is share ivy's cache, not it's local repository. Files are placed in ivy's repository by calling the publish task. Ivy has a clear storage distinction between these file types:
~/.ivy2/cache
~/.ivy2/local
Maven on the other hand mixes up both file types under the following directory:
~/.m2/repository
It would be a lot simpler to optimize your caching by installing a Maven repository manager like Nexus and configuring Maven and Ivy to use it. Nexus is a very efficient java process and simple to setup on your development machine.
Finally if you are determined to share caches, you could attempt to use the caches directive in the ivy settings file. It has "ivyPattern" and "artifactPattern" directives which suggest one can customize how the cached files are stored. To make this work you'll have to customize ivy. Maven has no flexibility in this area.
I am working on an existing application that uses ivy to manage dependencies, and the source comes with ivy.xml and ivysettings.xml files. I am trying to add my own jar to the build. What would be the easiest way to do this?
I tried adding a dependency to ivy.xml and I am not sure how to configure the repository directories. Maybe there are easy ways to do this? Any quick and dirty way will do.
The filesystem resolver in conjunction with the chain resolver should help you, assuming that you can modify the ivysettings.xml that you just inherited.
You can store your jars locally on your machine under your Local Ivy cache or your Shared Ivy cache. I believe it's $HOME/.ivy2/local and $HOME/.ivy2/shared and its in the same format as the $HOME/.ivy2/cache directory. If you use <ivy:publish/> Ant task to push your local jars to your local repository, they'll be accessible to all of your projects.
However, I recommend biting the bullet and doing things ...what's the technical term? oh yeah... The correct way.
Go ahead and setup a project wide Ivy/Maven repository where you can fetch your local jars the same way you fetch your third party jars. This way, there is no difference between your local jars, and the third party jars you're using. No one has to think where a particular Jar is located or adjust their Ivy configuration to get one jar or another.
Download either Nexus or Artifactory. You can set these repositories up so that all the third-party jars and your local jars are available as if they're all stored in the same server. You can even add in other jar repositories that are not centrally located.
I recommend Loughran's book Ant in Action. It has an excellent chapter on using Ivy. You can also look at my ivy.dir to see how I configure Ivy, so it's easily accessible to all of our projects.