Powered By Blogger

Mar 5, 2015

Setup svn server on ubuntu

This post describes about setting up the svn server on ubuntu.
  • Install Subversion
$ sudo apt-get install subversion libapache2-svn apache2

  • Configure Subversion
Create a directory for where you want to keep your subversion repositories:
$ sudo mkdir /subversion
$ sudo chown -R www-data:www-data /subversion/

  • Open the subversion config file dav_svn.conf (/etc/apache2/mods-available) and add the lines at the end as shown below. Comment or delete all the other lines in the config file:
#</Location>
<Location /subversion>
DAV svn
SVNParentPath /subversion
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
</Location>
  • Now create a SVN user using the following command. Here I create a new SVN user called sohani with password msc12345:

$ sudo htpasswd -cm /etc/apache2/dav_svn.passwd sohani
New password: 
Re-type new password: 
Adding password for user sohani

Use -cm parameter for the first time only, you can create another user with only -m parameter.
  • Create Subversion repository called sohani.repo under /subversion directory:

$ cd /subversion/
$ sudo svnadmin create sohani.repo
Restart Apache service:

$ /etc/apache2 sudo service apache2 reload
  • Open the browser and navigate to http://ip-address/subversion/sohani.repo. Enter the SVN username and password which you have created in the earlier step. In my case, username is sohani and password is msc12345.


Maven private remote repository setup


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 

$ 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, execute the following 

$ bash nexus/bin/nexus console  

Here nexus is attached with your console. If you close your console then the nexus server will be terminated. 

7.Then grant permission as follows

$ sudo chmod -R 777 nexus-2.11.1-01/
$ sudo chmod -R 777 sonatype-work/

8. Now in browser type the address - http://localhost:8081/nexus/. The default login user name is - admin and password is - admin123

9. To stop nexus. Just close the terminal or press Ctrl+C. 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>

10. And add these following line 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>

Building/Releasing projects with maven release plugin


This post describes about building/releasing projects with maven using the maven release plugin with org.wso2.maven:wso2-release-pre-prepare-plugin.


1. Checkout the svn repo and create two folders as tag and trunk.

2. Then you need to create a Maven Multi Module project called 'trunk' and then add following sections to the main pom.xml

<properties>
      <project.scm.id>my.svn.server</project.scm.id>
</properties>

 <scm>
      <connection>scm:svn:http://127.0.0.1/subversion/sohani.repo/test9/trunk</connection>
 <developerConnection>scm:svn:http://127.0.0.1/subversion/sohani.repo/test9/trunk</developerConnection>
<url>http://127.0.0.1/subversion/sohani.repo/test9/trunk</url>
</scm>


 <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.5</version>
          <configuration>
            <preparationGoals>clean</preparationGoals>
            <completionGoals>org.wso2.maven:wso2-release-pre-prepare-plugin:1.1.0:pre-prepare</completionGoals>
<!-- This must be set! The plugin throws a NPE when not set -->
             <tagBase>http://127.0.0.1/subversion/sohani.repo/test9/tags</tagBase>
          </configuration>
 </plugin>


   <distributionManagement>
<repository>
      <id>my-releases</id>
      <url>http://localhost:8081/nexus/content/repositories/releases/</url>
    </repository>
</distributionManagement>


  <pluginRepository>
<id>wso2-public</id>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public</url>
  </pluginRepository>



3. In settings.xml resides at .m2, you need to add below sections.

   <server>
      <id>my-releases</id>
      <username><nexus_uname></username>
      <password><nexus_password></password>
    </server>

  <server>
     <id>my.svn.server</id>
     <username><svn_uname></username>
     <password><svn_password></password>
   </server>

  <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://localhost:8081/nexus/content/groups/public</url>
    </mirror>

   <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>


   <activeProfile>nexus</activeProfile>


4. Then navigate to the checkout location (trunk) of the svn repo and execute below commands

mvn release:prepare -Dusername=<svn_uname> -Dpassword=<svn_password>

mvn release:perform

5. If you want to revert changes you can execute below commands

mvn release:rollback
mvn release:clean