开发者

Maven + Mercurial + Site Deploy issues

I'm trying to deploy my Maven generated site to a googlecode project using mercurial. When I do a

mvn site:deploy

I get Transfer error: org.apache.maven.scm.NoSuchCommandScmException: No such command 'list'.

Its like its trying to do a "svn list" even though I am using mercurial.

In my pom I have maven wagon and mercurial setup (I think correctly):

org.apache.maven.wagon wagon-scm 1.0-beta-6 org.apache.maven.scm maven-scm-provider-hg 1.4

Then for my site deploy I have a separate mercurial rep开发者_开发百科ository:

   <distributionManagement>
  <site>
   <id>googlecode</id>
   <name>googlecode site</name>
   <url>scm:hg:${project.site.scm}/</url>
  </site>
   </distributionManagement>

In my settings.xml I have:

  <servers>
  <server>
    <id>googlecode</id>
    <username>...</username>
    <password>...</password>
  </server>
  </servers>


Stumbled upon this question and thought I would provide an answer for anyone else as the documentation for how to do this is sparse:

For quite some time now I've been successfully hosting my website in a Google Code repository that uses Mercurial. It works well and I've had very little issues

First, you have to go to your project, tab "Administer", subtab "Source" and create a new repository called "site". Then, you have to commit and push at least one file, conveniently called "index.html" to that repository because "hg locate", which is called by the SCM plugin, fails on completely empty repositories.

I have this in my POM to deploy to http://site.MYREPO.googlecode.com/hg

<build>
    <plugins>
        ...
        <!--Deploy site with Mercurial (Hg)-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.0-beta-3</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.scm</groupId>
                    <artifactId>maven-scm-api</artifactId>
                    <version>1.5</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.maven.scm</groupId>
                    <artifactId>maven-scm-provider-hg</artifactId>
                    <version>1.5</version>
                </dependency>
            </dependencies>
        </plugin>
        ...
    </plugins>
</build>

<!--
    Distribution
-->
<distributionManagement>
    <!--Site deploy repository-->
    <site>
        <id>MYREPO.googlecode.com</id>
        <url>scm:hg:https://site.MYREPO.googlecode.com/hg</url>
    </site>
</distributionManagement>

You then have to tell Maven your username and password, so add this to your Maven settings.xml file (note the @ character is HTML encoded as Mercurial will choke on it normally)

<settings>
    <servers>
        <server>
            <id>MYREPO.googlecode.com</id>
            <username>MYEMAIL%40gmail.com</username>
            <password>MYPASSWORD</password>
        </server>
    </servers>
</settings>

Now you can mvn clean site site:deploy and visit http://site.MYREPO.googlecode.com/hg/index.html to get your complete maven site.


site:deploy uses the scp or file protocol for deploying a site to the server (see here). I configure this along normal ssh lines (authorized_keys, etc). And in the pom have something along the lines:

  <!-- The location for generating the website. -->
  <distributionManagement>
    <site>
      <id>website</id>
      <url>scp://username@server.com/path/to/deploy/directory/</url>
    </site>
  </distributionManagement>

It takes everything from the target/site directory and copies it across to the defined destination. However, the downside is, that it is up to me to ensure that what I have deployed is actually checked into my version control system. i.e:

hg push (use mercurial directly to push my changes to other developers).
mvn site:deploy (deploys from my local machine using scp).


First of all, I tried TheLQ's answer and even voted for that one (above), because it works for simple projects, especially if you also add wagon-scm and wagon-ssh dependencies to the maven-site-plugin and update all versions to the latest ;) With a multi-module project though I had an issue: each sub-module's site overwrites previously pushed content instead of nesting them (same problem with mvn deploy, i.e., deploying directly to a Hg managed remote maven repo does not create right folder hierarchy).

Therefore, here is an alternative solution, which also makes less commits to the remote repository (though, it requires a bit of manual work).

First, go to your Google Code project, https://code.google.com/p/MYPROJECT, tab "Administer", "Source" and create a new repository called, e.g., "site" (or how you'd like to call it). Then, you have to commit and push at least one file, conveniently called "index.html" to that repository.

Second, have the following in the parent project's pom.xml (only):

<distributionManagement>
<!-- ... other content ...-->
    <site>
        <id>MYPROJECT.googlecode.com</id>
        <name>MYPROJECT auto-generated site</name>
        <url>http://site.MYPROJECT.googlecode.com/hg</url>
    </site>
</distributionManagement>

and also -

<url>http://site.MYPROJECT.googlecode.com/hg</url>

Note: Aye, it's "http:" and not "https:"; in my example, the URL is NOT going to be used by Maven to actually deploy the site content there (I am not going to execute site-deploy); instead, will use mvn site site:stage (see below). Also, you do not have to touch the settings.xml (the one in ~/.m2/ on *nix systems).

Third, simply clone the remote ('site') repository to your local machine (target directory can be under the parent project's dir as well as under anywhere else's - just cd to THAT_DIR where you want it):

cd THAT_DIR
hg clone https://USERNAME@code.google.com/p/MYPROJECT.site/

Note: if it existed, you do not have to clone again, just do hg pull, hg update (optionally remove old content using hg rm * and commit). You can also use e.g. free SourceTree software instead of console.

Next, from the projects root, do normally (skip 'clean, install' goals if you did already before; I used Maven 3.0.5):

mvn clean install site site:stage -DstagingDirectory=FullPathTo/MYPROJECT.site

Finally, switch to the clone/stage directory, THAT_DIR/MYPROJECT.site, test the website locally (open index.html in a browser), and if happy do:

hg add *
hg commit -m "re-generated MYPROJECT"
hg push

Check it out at http://site.MYREPO.googlecode.com/hg/index.html and the sources and changes at https://code.google.com/p/MYPROJECT.site/

Done.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜