Maven read Ubuntu repository with windows developer machine - maven

We have our developer machines installed in a secure environment(say A) without internet access. We can move our .m2/repository folder created on the internet machine(say B) to a folder on a linux machine in the secured ENV and use that folder as a repository. Developers work on Windows in the same environment. the settings.xml looks like the below.
<mirror>
<id>repo1</id>
<name>Local proxy of central repo</name>
<url>file:////**%Linux_IP%**/maven/repository2</url>
<mirrorOf>*</mirrorOf>
</mirror>
<servers>
<server>
<id>repo1</id>
<username>uname</username>
<password>pwd</password>
</server>
</servers>
Error thrown:
Failed to read artifact descriptor for
org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not
transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5
from/to repo1 (file:////%Linux_IP%/maven/repository2): Repository
path \%Linux_IP%\maven\repository2 does not exist, and cannot be
created.
The above works fine if the repository is also on a windows machine but fails when the folder is on a Linux machine. As this is an initial release with very minor requirements, the org is not looking for a Nexus/Artifactory as an option at least for an year. Thanks!

Run a Nexus or Artifactory server. You can use it without internet connection and it has a nice, os independent way of managing the artifacts.
We do this ourselves. Our internal Nexus is disconnected from external repositories. If the developers need additional artifacts, we copy them from an external Nexus into our internal one.

Related

Configure Nexus connection for maven deployment

Im trying to gain some experience in working with Nexus and TeamCity.
To do so i set both servers up on my local machine and configured a pet project thats located on github.com in a private repo.
But i can't get my TC-Build to run because the Maven deploy step fails with following message.
[14:58:55][Step 2/2] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project Worm: Failed to deploy artifacts: Could not transfer artifact org.test.worm:Worm:jar:1.0.0 from/to local_nexus (http://localhost:8081/repository/org.test): Transfer failed for http://localhost:8081/repository/org.test/org/test/worm/Worm/1.0.0/Worm-1.0.0.jar 401 Unauthorized
Seems like it fails due to wrongly configured authorization but i can't find the mistake.
In my projects pom.xml it is configured like this
<distributionManagement>
<repository>
<id>local_nexus</id>
<name>Deployment</name>
<url>http://localhost:8081/repository/org.test</url>
</repository>
</distributionManagement>
and in my mavens settings.xml like this
<server>
<id>local_nexus</id>
<username>admin</username>
<password>admin</password>
</server>
Im using the default admin user (user/pw is correct, logging into nexus with the same user) that is created when installing nexus. Same user that created the repository.
TC running under localhost:8080 and Nexus under localhost:8081
Please tell me what i configured wrongly or what i forgot.
Using mvn help:effective-settings i could confirm that the settings.xml was configured correctly. But it made me realize that my TeamCity Server was using a different (its own) maven instance than my local machine. So the solution was to either set the maven-home for TeamCity or to configure the settings.xml of the other maven instance.
Stupid mistake i should have noticed way sooner.

How to Change Maven repository to inbuilt repository in same network

In our project we need to setup a repository in a remote machine and I need to point to that repository. I have tried changing settings.xml.
But that didn't work. Then I added repository directly in pom.
This works. But still I am seeing the artifacts are downloaded from central repository. When I checked the effective pom, I am seeing that central repository is been mentioned along with mentioned internal repository
I dont need artifacts to be downloaded from central repository. Instead I need to download from my remote repository. How can I achieve it. TIA :)
You can force Maven to use a single repository by having it mirror all repository requests. The repository must contain all of the desired artifacts, or be able to proxy the requests to other repositories. This setting is most useful when using an internal company repository with the Maven Repository Manager to proxy external requests.
To achieve this, set mirrorOf to *.
<settings>
...
<mirrors>
<mirror>
<id>internal-repository</id>
<name>Maven Repository Manager running on repo.mycompany.com</name>
<url>http://repo.mycompany.com/proxy</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
more details here

Maven cannot pull jars from Mirros

We have a central repository within intranet. I set mirror as follow. The issue is when I try to download a dependency that is not available in my local repository, the dependency cannot be downloaded completely. Only .lastUpdated file is downloaded in directory. I cannot figure out whey this weird thing happened. But it I comment the mirror setting, the dependency could be downloaded correctly. But I need some ourselves developed dependencies that are residing on central repository. That means I cannot bypass the central repository to search on internet. Does anyone come across this creepy issue?
<mirror>
<id>central-proxy</id>
<name>Central Repo</name>
<url>http://*.*.*.*.*/artifactory/repo</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>

Maven private remote repository setup

I'm trying to set up a private remote repository for our team. Now the repository serves the following with so far I have tried -
When a 'mvn compile' is issued, then it searches dependencies in "~/.m2". If it is not found there then it goes to the remote private repository and when the dependencies still absent here then it goes to the central repository.
Before compilation, I have to put all dependencies in our private (and remote) repository along with checksum and metadata.
When we need an artifact(eg - spring-mvc), we need to put it in the remote private repository along with all dependencies of that artifact (spring-mvc). In this case "spring-mvc" is downloaded from our remote private repository. But the dependencies of "spring-mvc" are not downloaded from our remote private repository. They are downloaded from the central repository.
Now what I am trying to do are -
Configuring a private remote repository 'R' in such a way that I do not have to put all the dependencies to it by hand. When a "mvn compile" issued then first of all; dependencies are searched in "~/.m2" if not found then it goes to the private remote repository 'R'. If the dependencies are found in 'R' then "~/.m2" will get it from 'R'. If the dependencies are not found in 'R' then these dependencies are downloaded from the central repositories and keep the dependencies in 'R' for further uses. After that '~/.m2' will get them from 'R'. Here I do not need to put the dependencies in our remote private repository 'R' by hand.
'~/.m2' will get all dependencies of "spring-mvc" (which is the main dependency mentioned in my project's pom.xml) from the remote private repository 'R' and 'R' will get them from the respective central repository.
Can anyone suggest some way/or tutorial for reference to meet these two above targets? Thanks in advance.
EDIT : I have tried with Nathaniel Waisbrot's answer and nexus-2.7.0-06-bundle. After hours of endeavors, I am able to set it up while I am using jre-7. With jre-6, nexus cannot be started. But our project is deployed with JDK-6. We do not want to the change the current jre version. With jre-6 apache-archiva is OK. But I am not sure whether I can achieve all the goals in previous section. Is there any archiva user/expert who can tell me whether I can meet these goals in the previous section?
I have setup nexus for mirroring my maven local repository (at ~/.m2/repository.) Since this post is still visited by a lot of people, I think it would be helpful for others if I share how I configured nexus as a repository manager. This procedure works perfectly for me in Ubuntu 12.04. Here it is -
1. Download nexus-2.11.1-01-bundle.tar.gz or latest version of nexus oss.
2. Extract the tar file in you home directory-
$ tar -xvf nexus-2.11.1-01-bundle.tar.gz
Now you will get two directories - nexus-2.11.1-01 and sonatype-work in your home directory.
3. Copy these two directories to /usr/local/ directory (they can be copied to other place) -
$ cp -r nexus-2.11.1-01 /usr/local/
$ cp -r sonatype-work /usr/local/
The executable/configuration files related to nexus are stored in nexus-2.11.1-01 directory and the jar file mentioned in pom.xml are stored in sonatype-work directory.
These jar files are mirror of your ~/.m2/repository. First time you issue a mvn package command then all the jars are stored here. After then when you issue mvn package again then all jars are downloaded from the nexus repository instead of downloading from the central repository.
4. Go to the /usr/local/ directory -
$ cd /usr/local/
5. Create a link to nexus-2.11.1-01 -
$ sudo ln -s nexus-2.7.0-06 nexus
6. Now to run nexus type the following in terminal -
$ bash nexus/bin/nexus console
Here nexus is attached with your console. If you close your console then the nexus server will be terminated. When you are trying to run nexus for a Ubuntu server machine then you may use screen.
Note: While trying to run nexus by using the command above there may occur 2 problems. If you do not found any problem then skip next 2 steps (step - 7 and 8)
7. First problem may occur due to insufficient permission. Read the error message and take necessary steps. But as a quick solution you may do this -
$ sudo chmod -R 777 nexus-2.11.1-01/
$ sudo chmod -R 777 sonatype-work/
8. If you are using any jdk version lower than java 7 than the following error message may be shown -
wrapper | Launching a JVM... wrapper | JVM exited while loading the
application. jvm 1 | Exception in thread "main"
java.lang.UnsupportedClassVersionError:
org/sonatype/nexus/bootstrap/jsw/JswLauncher : Unsupported major.minor
version 51.0
In this case use jdk7 to run the command mentioned in step 6. In ubuntu its pretty easy. Assuming you have two jdk - jdk6 and jdk7. Your project runs on jdk6. Then only for running nexus you may do this from your terminal (assuming your jdk7 in /usr/lib/jvm/jdk1.7.0_45 directory) -
$ export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45
$ export PATH=$JAVA_HOME/bin:$PATH
9. Now in browser type the address - http://localhost:8081/nexus/. If step 1 to 6 (if errors occurred then step 1 to 8) are done perfectly you may successfully find the login screen. The default login user name is - admin and password is - admin123
10. Stop nexus. Just close the terminal or press Ctrl+C at step 6's terminal. In you ~/.m2 directory create an empty file named - settings.xml. Copy the following content into this settings.xml file -
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
11. And add these following lines in your project's pom.xml file -
<distributionManagement>
<snapshotRepository>
<id>my-snapshots</id>
<name>My internal repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>my-releases</id>
<name>My internal repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
</distributionManagement>
Sonatype Nexus does everything you want, needs very little configuration for what you're asking, and has a nice interface. There's some details on the basic setup under the question "Maven Internal Repository, Is it Really This Hard?"
Basically, you can set up Nexus as a caching repository: your Maven client will only visit the internal repository. When the internal repository can't find an artifact, it goes to Central (or any other external repositories you define), fetches it for you, and stores it for later.
This is cool because if you want to transition from a grab-whatever-dependencies-you-want free-for-all to a locked-down environment, Nexus makes it easy. You set it up to pull from Central, run your build from a clean machine (forcing Nexus to ingest all the current Central dependencies) and then turn off the proxy-repo feature (so any new/changed dependencies will be managed by devops).
What you've described is pretty much the default configuration of most repository managers, including Archiva. Does the following help in getting it set up to use from Maven?
http://archiva.apache.org/docs/1.3.6/userguide/using-repository.html

Difference between using a single repository and a single mirror

The maven documentation says:
http://maven.apache.org/guides/mini/guide-mirror-settings.html
Using A Single Repository. You can force Maven to use a single
repository by having it mirror all repository requests. The repository
must contain all of the desired artifacts, or be able to proxy the
requests to other repositories. This setting is most useful when using
an internal company repository with the Maven Repository Manager to
proxy external requests.
To achieve this, set mirrorOf to *.
<settings>
...
<mirrors>
<mirror>
<id>internal-repository</id>
<name>Maven Repository Manager running on repo.mycompany.com</name>
<url>http://repo.mycompany.com/proxy</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
I don't understand this paragraph.
Shouldn't it be something like this?
Using A Single Mirror You can force Maven to use a single
mirror by having it mirror all repository requests. The mirror must contain all of the desired artifacts for all the
repositories, or be able to proxy the requests to other
repositories. This setting is most useful when using an internal
company repository with the Maven Repository Manager to proxy external
requests. To achieve this, set mirrorOf to *.
<settings>
...
<mirrors>
<mirror>
<id>internal-mirror</id>
<name>Maven Mirror Manager running on mirror.mycompany.com</name>
<url>http://mirror.mycompany.com/proxy</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
Where is my miss-understanding?
I mean, <mirror><id>internal-repository</id>... seems just wrong to me.
Mirror means a repository that is used as a passerelle/proxy to an other repository.
When using a repository manager like Nexus, Artiafactory, Archiva... you dispose of one local entreprise repository wich proxifies remotes ones.
So there is no need to declare too many repositories in your pom or setting.xml. Using Just one mirror which redirect all requests to the repository manager you have will be sufficient.
That is the meaning of the documentation.
As maven documentation says:
Repositories can be declared inside a project, which means that if you have your own custom repositories, those sharing your project easily get the right settings out of the box. However, you may want to use an alternative mirror for a particular repository without changing the project files.
For repositories in settings.xml, declaring mirrors for them is redundant because you can just replace the repositories directly. You should use mirrors for repositories in pom.xml.
For example. Project X is a public project that list all the repos it required in its pom.xml.
Most people can just download and build the project directly.
Alex wants to build the project on his working PC at company, and his company has an internal enterprice repo. So he uses the company repo in his settings.xml as a mirror for the project repos.
Bob cannot access some project repos directly due to connection issue. He can use other public mirrors for that repo.
Repos in pom.xml is used as default implements and mirrors should be used for special cases.

Resources