Gradle init using corporate maven repo - gradle

I am trying to convert a maven multi module project to a gradle project using gradle init. I am using a corporate maven repository and am not allowed to download artifacts directly from the internet. I need to route all requests through the corporate maven repo.
I am using Windows 7. I tried adding a init.gradle script in the .gradle folder under my user home directory. However when I try the command gradle init, it detects the pom, asks to convert, but then fails in resolving the dependencies.
Can somone help?

Related

creating spring boot project without maven

I am working recently with spring boot framework
my problem is that I need to set up to environment in a device that has no internet
I have searched A lot but all I found is using maven that will handle the processes of downloading all the dependencies
put I need to add the required dependencies like the old way when you download the jar files and add them to the class-path
is there a way to do so with STS
or is there a way to change where the maven download the dependencies to be from local instead of internet
Never used STS but I assume it uses maven/gradle under the hood.
You can set up local repository and point maven/gradle to it. For example you could use Nexus:
https://www.sonatype.com/products/repository-oss
Another way is to pull dependencies (they get downloaded when you do maven or gradle build and are saved under ~/.m2 or ~/.gradle directories), then copy your ~/.gradle or ~/.m2 directory to the PC with no internet and build offline. With gradle it looks like this.
./gradlew build --offline

Integrate the local maven plugin with remote repository

I have created a simple maven plugin and installed it in my local repo(.m2). Now I want to use that plugin with a git repo(maven project). How can I do that?
Currently, I am trying to build my git repo using Jenkins and it throws below error-
[ERROR] Plugin sample.plugin:hello-maven-plugin:0.0.1-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact sample.plugin:hello-maven-plugin:jar:0.0.1-SNAPSHOT
I believe simply changing the pom file of my git repo won't work. What should I do so that it resolves the plugin dependency by looking into the .m2 dir first
Your Jenkins probably deploys to a Nexus or Artifactory server. That server is also the right place to manage your plugin.

How to change maven repository for intelliidea's plugins?

I'm using Intellij idea build: IU-171.3780.107 in Ubuntu 16.04. I need to use docker plugin.
At beginning docker plugin need to download dependencies for maven central (http://maven.central.org). I am behind of a proxy and it deny my access to this site
Intellij idea error:
Failed to download client libraries: Failed to download 'http://central.maven.org/maven2/com/github/docker-java/docker-java/3.0.0/docker-java-3.0.0.jar'
but i have guaranty access to another maven repository linked to maven central
How i change maven repository address, used by intellij idea for plugins download, to my maven local config in .m2 (setting.xml)
Note: I don't have problem with dependencies for my own project because it use successfully my setting in .m2 directory, the problem is with a intellij idea plugins.

Can we use Maven Dependency in Gradle Project Remotely

I am trying to host maven Dependency basically which I can use in Some other Gradle project.
I have also try this locally but I want to do it remotely.
I also try to do this in some other manner - I just host one jar file in tomcat server and tried to download in my gradle project.
"http://10.10.177.157:8080/face_rec/images/jmf-2.1.1e.jar" this is the hosted jar path in which we can eaisly download jar file by hitting this ulr.And "C:/Users/USERNAME/.m2/repository/commons-io/commons-io/2.2/commons-io-2.2.jar" this is my local .m2 repository.
In this gradle project I can easily download the jar files using compile files ("C:/Users/USERNAME/.m2/repository/commons-io/commons-io/2.2/commons-io-2.2.jar") but I am not able to download hosted jars i.e - http://10.10.177.157:8080/face_rec/images/jmf-2.1.1e.jar
Can someone give me any idea about this that how can it is possible.
thanks

Maven install local usage when using a repository manger

I am lacking some basic understanding of using a repository manager for our projects. What I don't know is how, if I use a repository manager, if I run a local install command Maven doesn't deploy the package to something like a shared Nexus instance. I seem to have some confusion between local repositories and shared ones when using a repository manager.
Apologies for the naivity and for not testing this myself. We have started versioning our application and using a shared file system approach to getting artifacts and are left with a few questions about what, within the scope of what we are currently doing, will be gained by using a repository manager instead. We do use TeamCity as a build server which is deploying to that currently used file system. I need to know some answers to a few questions before POCing a repo manager.
install is specific to the local repository.
From Maven's point of view whether a remote repository is hosted by your repository manager or is completely external has no relevance - when you're adding your artifact to any kind of remote repository, you need to use the deploy plugin (or release for non-trivial deployments).
Repository managers usually generate instructions on configuring your projects for deployment to a hosted repo.
maven defines a lifecycle (clean, compile, install, deploy...). There are default mappings when you execute "mvn install". So maven knows which plugins to execute for that maven goal.
The Introduction page gives a good overview what happens for each phase (goal) and what the default plugins are: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
In your case: mvn install will copy the artifacts into the local maven repository to be shared by other projects you have locally.
If you want to share artifacts with other developers on other locations "mvn deploy" will copy the artifacts to the remote repository. Note you need to configure the distributionManagement section in the pom.xml to be able to do that.
The normal maven setup should look like this:
project -> local repository -> private remote repository -> public remote repository
Project: in the simplest case your project consists of source files and a configuration file (pom.xml). The project may depend on third party libraries like junit. The jar files of the libraries are not stored in your project directory, only the information which jars are needed.
mvn package
This command creates a jar out of your project an places it in the target/ folder of your project.
Local Repository: This is a maven repository stored locally on your machine. It normally resides in ~/.m2/repository/. Every dependency you are using in your project will be stored in this repository. On compiling your project, maven will use the jar files from this location.
mvn install
This command creates a jar file and copies it to your local repository: ~/.m2/repository/groupId/artifactId/version/project.jar. Now you can use this jar in different independent projects as a dependency, but only your machine.
Private Remote Repository: Most of the time this is a Nexus in your company network. This server allows to share the build project across developers. Your TeamCity server builds the jar and copies it to your nexus server. Beyond this the nexus server works like a proxy, e.g. A Developer needs junit-4.1.1.jar, so the server looks for it on public remote repositories and caches it.
mvn deploy
This command builds a jar and sends it to your nexus server ('to your private remote repository') After that every developer inside your company network can access the jar.
Public Remote Repository: These are repositories available on the internet which contain several jar files, e.g. maven.codehaus.org
Summary:
If you call mvn compile maven looks for the dependencies in your local repository. If maven can't find them, it will ask the (private/public) remote repository, and copy the files to the local repository.
You should not synchronize a local repository over network, since this type of repository is not targeted at such use and may break in some obscure way.
What you need is a mvn deploy - copies the final package to the remote repository for sharing with other developers and projects
mvn install you tried will just build and install the project in your local ~/.m2 repository. It will_not publish the artifacts to your nexus repository which you have configured.
Both install and deploy are valid build phase - meaning it executes all previous phases. Please refer to Maven docs below for more understanding.
From maven documentation:
the default Maven lifecycle has the following build phases (for a complete list of the build phases, refer to the Lifecycle Reference):
validate - validate the project is correct and all necessary information is available
compile - compile the source code of the project
test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package - take the compiled code and package it in its distributable format, such as a JAR.
integration-test - process and deploy the package if necessary into an environment where integration tests can be run
verify - run any checks to verify the package is valid and meets quality criteria
**install** - install the package into the local repository, for use as a dependency in other projects locally
**deploy** - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

Resources