Monday, February 20, 2012

Scala Overview Presentations

I would like to publish presentations from a small training I've given in the company I work. It is better to hear the explanation, but the slides still can be useful Lecture Lecture 2

Friday, February 10, 2012

Google Protobuf Maven Plugin

Recently I have a Maven plugin, that allows you to compile Google Protobuf proto files with Maven. The Main difference form other plugins that it works.

Enjoy http://igor-petruk.github.com/protobuf-maven-plugin/

Future release will download protoc.exe automatically.

Usage:

Put your *.proto to src/main/protobuf and don't forget to add 'protoc' to your path. (version 2.4.0 in this example)
<dependencies>
        <dependency>
                <groupId>com.google.protobuf</groupId>
                <artifactId>protobuf-java</artifactId>
                <version>2.4.0a</version>
        </dependency>
</dependencies>
<build>
        <plugins>
                <plugin>
                        <groupId>com.github.igor-petruk.protobuf</groupId>
                        <artifactId>protobuf-maven-plugin</artifactId>
                        <version>0.6.2</version>
                        <executions>
                                <execution>
                                        <goals>
                                                <goal>run</goal>
                                        </goals>
                                </execution>
                        </executions>
                </plugin>
        </plugins>
</build>

A couple of useful archetypes in Maven

Hi, I was doing some open source lately. Feel free to examine my GitHub page, any suggestions are welcomed. I have published some nice Maven archetypes that allow you to create ready-to-run Java and Scala Maven applications with a single command.

FAQ

  • Why should I make Maven project instead of IDE project?
    • Shortly speaking: Maven gives you more. It will download any Java library or Maven Plugin existing out there automatically if you add reference to pom.xml. It will manage site generation, testing, releasing and much more. If you give your source code to someone else, they will be able to build your project without setting up the environment, downloading libraries or changing their favorite IDE. Don't make IDE projects
  • What is a Maven Archetype?
    • Project Template. It allows you to create Maven project with some configuration by default. You just enter the name of the archetype, it gets downloaded, bootstrapped and magic happens.
  • How is your Java archetype different from Quickstart?
    • It will make your project automatically executable with 'java -jar', so after you build it, you can give the jars away to people.
  • Doesn't the method shown on this page do the same thing?
    • No, I just adds the dependency to jars JAR manifest, but where are these jars ? My archetypes use the same method, but plus it does dependency:copy, so all your dependencies appear in target/lib. Yes, you can do the same. Only I have done it for you, it is not a short pom.xml.
  • Something else?
    • Yes, compiler plugin that compiles Java 6 by default, JUnit 4.10 with a simple test
  • Why should I use your scala archetype?
    • First, everything that I said about java archetype applies here. Second, it does not require Scala installation. It is compiled by maven plugin and a version of Scala can be changed in one line. No more Scala SDK manual download.
  • I don't like something about your archetype?
    • Contact me, cuz this is only a first version, I would like to make these archetypes better.
  • What files should I give away after I build the project.
    • The main jar in target and lib subfolder. Run with java -jar
  • Why does lib contain my test dependencies?
    • This is small bug (feature) in copy:dependency. 'scope' is not handled correctly yet.
So let's try it, archetypes are already at Central

Create Java Project

mvn archetype:generate -DarchetypeGroupId=com.github.igor-petruk.archetypes -DarchetypeArtifactId=maven-archetype-executable -DarchetypeVersion=0.1

Create Scala Project

mvn archetype:generate -DarchetypeGroupId=com.github.igor-petruk.archetypes -DarchetypeArtifactId=maven-archetype-scala-executable -DarchetypeVersion=0.1

If you are a Unix user, I would suggest put these commands in scripts