1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt-doc.git synced 2025-04-25 03:57:11 -07:00

Update archetype doc.

This commit is contained in:
Cedric Beust 2016-02-11 21:30:38 -08:00
parent 81ef95763e
commit b55a44b42f
4 changed files with 43 additions and 60 deletions

View file

@ -454,10 +454,10 @@ New versions found:
</tr>
<tr>
<td><code>--init</code></td>
<td>Boolean</td>
<td>false</td>
<td>Initialize a project for Kobalt.</td>
<td>This option will create a build file in the current directory (unless one already exists) and will install the Kobalt wrapper.</td>
<td>Comma-separated strings</td>
<td>null</td>
<td>Initialize a project for Kobalt with the given archetypes.</td>
<td>The parameter to this argument is a list of archetype names separated by commas, e.g. <code>"java,myProject"</code>. Each archetype will be invoked in order so they can generate their files.</td>
</tr>
<tr>
<td><code>--log</code></td>

View file

@ -58,72 +58,55 @@ unzip kobalt-xxx.zip
</p>
<pre class="brush:plain">
cd ~/java/project
$KOBALT_HOME/kobaltw --init
$KOBALT_HOME/kobaltw --init java
</pre>
<p>
This command will do two things:
</p>
<ol>
<li>Create a default <code>kobalt/src/Build.kt</code> file based on what was found in your project.
<li>Install the Kobalt Wrapper in your current directory (a script called <code>kobaltw</code>) and a few additional files in the <code>kobalt/wrapper</code> directory. From now on, you can just use <code>./kobaltw</code> to build and you can ignore <code>$KOBALT_HOME</code>.
</ol>
<p>
You can now attempt to build your project with Kobalt:
</p>
<li>Create a default <code>kobalt/src/Build.kt</code> suitable for a brand new Java project.
<li>Install the Kobalt Wrapper in your current directory (a script called <code>kobaltw</code>) and a few additional files in the <code>kobalt/wrapper</code> directory. From now on, you can just use <code>./kobaltw</code> to build and you can ignore <code>$KOBALT_HOME</code>.
</ol>
<p>
You can now attempt to build your project with Kobalt:
</p>
<pre class="brush:plain">
./kobaltw assemble
</pre>
If your project follows a regular build structure (e.g. <a href="https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html">Maven's hierarchy</a>), this should compile your file and create a .jar file. If not, you will have to make a few edits to your <code>Build.kt</code>.
As of this writing, Kobalt supports Java and Kotlin projects.
If your project follows a regular build structure (e.g. <a href="https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html">Maven's hierarchy</a>), this should compile your file and create a .jar file. If not, you will have to make a few edits to your <code>Build.kt</code>.
As of this writing, Kobalt supports Java and Kotlin projects.
<h2 class="section" id="edit">3. Edit kobalt/src/Build.kt</h2>
<h2 class="section" id="edit">3. Edit kobalt/src/Build.kt</h2>
Here is the <code>Build.kt</code> for the <a href="https://github.com/hhariri/wasabi/blob/master/kobalt/src/Build.kt">Wasabi HTTP framework</a>:
<p>The build file generated by default might need some editing before you can build your project, so take a look at it and adjust whatever is necessary (e.g. package name, version, etc...)</p>
<p>
Here is the <code>Build.kt</code> for the <a href="https://github.com/cbeust/jcommander/blob/master/kobalt/src/Build.kt">JCommander project</a>:
</p>
<pre class="brush:java">
import com.beust.kobalt.*
import com.beust.kobalt.plugin.packaging.assemble
import com.beust.kobalt.plugin.kotlin.*
import com.beust.kobalt.plugin.java.*
import com.beust.kobalt.plugin.packaging.*
import com.beust.kobalt.plugin.publish.*
val kotlinVersion = "1.0.0-beta-4583"
val p = kotlinProject {
name = "wasabi"
group = "com.example"
val jcommander = project {
name = "jcommander"
group = "com.beust"
artifactId = name
version = "0.1"
version = "1.54"
// Tell Kobalt to also search here for dependencies
val repos = repos("http://oss.sonatype.org/content/repositories/snapshots")
dependencies {
compile("org.jetbrains.kotlin:kotlin-stdlib:" + kotlinVersion,
"org.jetbrains.kotlin:kotlin-reflect:" + kotlinVersion,
"io.netty:netty-all:4.0.31.Final",
"commons-codec:commons-codec:1.6",
"commons-logging:commons-logging:1.1.1",
"joda-time:joda-time:2.3")
}
// Test dependencies
dependenciesTest {
compile("junit:junit:4.9",
"org.mockito:mockito-all:1.9.5",
"org.apache.httpcomponents:httpclient:4.5.1")
compile("org.testng:testng:6.9.9")
}
// Tell kobalt to produce a fat jar and also the artifacts required for Maven
assemble {
jar {
fatJar=true
name = "wasabi-fat-" + version + ".jar"
}
mavenJars{
mavenJars {
}
}
}
</pre>
jcenter {
publish = true
}
}</pre>
<h2 class="section" id="idea-plugin">4. Sync your build file</h2>
<p>

View file

@ -111,7 +111,7 @@ class JavaPlugin : ICompilerContributor, IDocContributor {</pre>
<pre class="brush:java">
class JavaBuildGenerator: IInitContributor {</pre>
<p>
This class is declaring that it wants to take part in the <code>--init</code> selection process, discussed below.
This class is declaring that it wants to take part in the <code>--init</code> process (i.e. it can generate an archetype), discussed below.
</p>
<h2 class="section" id="actor-list">List of plug-in actors</h2>
<p>
@ -187,10 +187,11 @@ class JavaBuildGenerator: IInitContributor {</pre>
<tr>
<td><code><a href="https://github.com/cbeust/kobalt/blob/master/src/main/kotlin/com/beust/kobalt/api/IInitContributor.kt">IInitContributor</a></code></td>
<td><a href="https://github.com/cbeust/kobalt/blob/master/src/main/kotlin/com/beust/kobalt/api/IPluginActor.kt"><code>IContributor</code></a> </td>
<td>Kobalt supports the <code>--init</code> command line parameter, which generates a default build file
based on the files found in the current directory. Any plug-in that wants to be part of this process need
to implement this interface. In this case, both the Java and Kotlin plug-ins define such a contributor
but future plug-ins might use this contributor to generate their own build file: Android, Ceylon, Spring, etc...
<td>When invoked with <code>--init</code> followed by archetype names separated by commas,
Kobalt will invoke each of these contributors so they can generate their files.
Archetypes are useful to create projects from scratch with a minimal number of
files to get started. For example, the "java" archetype will generate a `Build.kt`
file suitable for a brand new Java project.
</td>
</tr>
<tr>

View file

@ -75,13 +75,12 @@
$ mkdir linecount
$ cd linecount
$ mkdir -p src/main/kotlin/com/beust/plugin/linecount
$ touch src/main/kotlin/com/beust/plugin/linecount/Main.kt
$ $KOBALT_HOME/kobaltw --init
$ $KOBALT_HOME/kobaltw --init kotlin
</pre>
<p>
I create an empty <code>Main.kt</code> in the example above so that calling <code>./kobaltw --init</code> will detect the project as a Kotlin one. This way, the <code>Build.kt</code> file generated is already configured for Kotlin. Since we will be publishing this project to a Maven repository, we need to make sure that its <code>group</code>, <code>artifactId</code> and <code>version</code> are correct. The only thing that the generator can't guess is the <code>group</code>, so let's go ahead and fix it:
</p>
<p>
<code>./kobaltw --init kotlin</code> creates an empty Kotlin project. Since we will be publishing this project to a Maven repository, we need to make sure that its <code>group</code>, <code>artifactId</code> and <code>version</code> are correct. The only thing that the generator can't guess is the <code>group</code>, so let's go ahead and fix it:
</p>
<pre class="brush:java">
val project = kotlinProject {