<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scala-fr &#187; emacs</title>
	<atom:link href="http://www.scala-fr.org/tags/emacs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scala-fr.org</link>
	<description>communauté francophone autour du langage Scala</description>
	<lastBuildDate>Sat, 10 Oct 2009 08:01:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Initialiser un nouveau projet Scala avec Maven 2</title>
		<link>http://www.scala-fr.org/initialiser-un-nouveau-projet-scala-avec-maven-2/</link>
		<comments>http://www.scala-fr.org/initialiser-un-nouveau-projet-scala-avec-maven-2/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 16:25:36 +0000</pubDate>
		<dc:creator>Maxime Biais</dc:creator>
				<category><![CDATA[Compilation]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.scala-fr.org/?p=121</guid>
		<description><![CDATA[Introduction
Dans un précédent article, nous vous présentions sbt. Cette fois nous allons voir comment gérer un projet Scala avec maven.
Le plus simple, c&#8217;est de démarrer de zéro, et d&#8217;initialiser un projet en utilisant un archetype prédéfini. Cet archetype est un template de projet qui contient le minimum pour démarrer :

La structure de répertoire de projet
Le [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.scala-fr.org%2Finitialiser-un-nouveau-projet-scala-avec-maven-2%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.scala-fr.org%2Finitialiser-un-nouveau-projet-scala-avec-maven-2%2F" height="61" width="51" /></a></div><h1>Introduction</h1>
<p>Dans un <a href="http://www.scala-fr.org/sbt-scala-build-tool-ou-comment-compiler-son-projet-scala/">précédent article</a>, nous vous présentions sbt. Cette fois nous allons voir comment gérer un projet Scala avec <code>maven</code>.</p>
<p>Le plus simple, c&#8217;est de démarrer de zéro, et d&#8217;initialiser un projet en utilisant un archetype prédéfini. Cet archetype est un template de projet qui contient le minimum pour démarrer :</p>
<ul>
<li>La structure de répertoire de projet</li>
<li>Le pom.xml</li>
<li>Des fichiers sources quasiment vide (un main(), et un test pour scala-archetype-simple)</li>
</ul>
<h1>Initialisation d&#8217;un projet</h1>
<p>Pour l&#8217;initialisation d&#8217;un projet nous allons utiliser le plugin maven archetype (disponible dans le repository officiel de maven). Nous allons passer en paramètre de ce plugin, un lien vers une liste d&#8217;archetype : scala-tools (pour le moment, seul site à proposer des archetypes pour Scala).</p>
<pre>$ mvn archetype:generate -DarchetypeCatalog=http://scala-tools.org
    [...]
    Choose archetype:
    1: http://scala-tools.org -> scala-archetype-simple (A simple scala project)
    2: http://scala-tools.org -> lift-archetype-blank (A blank/empty liftweb project)
    3: http://scala-tools.org -> lift-archetype-basic (A basic liftweb project (with DB, css, ...))
    Choose a number:  (1/2/3): 1
</pre>
<p>Le plugin va ensuite vous posez quelques questions pour générer le pom.xml. Sélectionner le projet scala de base (1) à moins que vous soihaitiez faire du <a href="http://liftweb.net/">lift</a>.</p>
<p>Le projet ainsi initialisé contient déjà quelques dépendances et quelques plugins pratiques pour une bonne gestion d&#8217;un projet Scala :</p>
<ul>
<li>Un lien vers le repository maven de bibliothèques et de plugins Scala-tools: <a href="http://scala-tools.org/repo-releases">http://scala-tools.org/repo-releases</a></li>
<li>Une dépendance vers jUnit</li>
<li>Une dépendance vers <a href="http://code.google.com/p/specs/">specs</a></li>
<li>Le plugin <a href="http://www.scala-tools.org/mvnsites/maven-scala-plugin/">maven-scala-plugin</a></li>
</ul>
<h1>Quelques actions de maven-scala-plugin</h1>
<p>Les <em>goal</em> maven classiques sont biensûr fonctionnels (compile, package, release, &#8230;).</p>
<p>Le goal scala, propose différentes actions notamment :</p>
<ul>
<li>
<p>Lancer une application</p>
<pre>$ mvn scala:run -DmainClass=org.example.MyClass
</pre>
</li>
<li>
<p>Générer la documentation de l&#8217;API</p>
<pre>$ mvn scala:doc
</pre>
</li>
<li>
<p>Lancer le mode compilation continue (lance une boucle infinie qui compile toutes les sources qui sont sauvegardées, très pratique si vous développez avec un éditeur de texte simple type emacs ou vi)</p>
<pre>$ mvn scala:cc
</pre>
</li>
</ul>
<p><em>Note pour les utilisateurs d&#8217;emacs</em> : vous pouvez passer en compilation-mode avec <a href="http://vastusutra.blogspot.com/2007/06/getting-emacs-and-maven-2-to-play.html">cette astuce pour lancer maven</a>, puis lancer <code>mvn scala:cc</code>, je vous conseil aussi d&#8217;ajouter cette ligne dans votre .emacs.el : <code>(setq compilation-scroll-output t)</code> pour enclencher le scrolling automatique de la fenetre de compilation. Avec ça (et les ctags pour la complétion), vous pouvez jeter Eclipse et NetBeans <img src='http://www.scala-fr.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . Vous pouvez aussi utiliser le flymake-mode beaucoup plus pratique mais malheuresement un peu lent à cause de l&#8217;utilisation de maven en arrière plan.</p>
<p>Je n&#8217;ai rien contre Eclipse ou Netbeans, mais mon process emacs ne dépasse jamais 30Mo de RAM et il ne s&#8217;arrête pas inopinément.</p>
<p>Plus de détails sur la page de <a href="http://www.scala-tools.org/mvnsites/maven-scala-plugin/usage.html">documentation de maven-scala-plugin</a>.</p>
<h1>Ajouter des dépendances</h1>
<p>C&#8217;est du maven classique. Pour ajouter une dépendance, éditer votre fichier <code>pom.xml</code> et ajouter les groupId / artifactId / version dont vous avez besoin dans <code>project->dependencies</code>. Si je veux par exemple ajouter la dépendance vers scalacheck, il me suffit d&#8217;ajouter :</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
[...] 
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.scala-tools.testing<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>scalacheck<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
[...]
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Note : ScalaCheck est disponible sur le repository maven scala-tools (ajouté par défaut à l&#8217;initiation du projet avec l&#8217;archetype scala-archetype-simple).</p>
<h1>Démonstration</h1>
<p>Une démonstration de l&#8217;utilisation de mvn dans emacs, en utilisant <code>mvn archetype:generate</code> pour initialiser un projet exemple.</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/M9sFtoFzl3w&#038;hl=en&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/M9sFtoFzl3w&#038;hl=en&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
     ]]></content:encoded>
			<wfw:commentRss>http://www.scala-fr.org/initialiser-un-nouveau-projet-scala-avec-maven-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
