|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <title>Maven tile | Getting started | Ebean</title> |
| 5 | + <meta charset="utf-8"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> |
| 7 | + <link rel="shortcut icon" href="/images/favicon.ico"> |
| 8 | + <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Source+Sans+Pro|Ubuntu&display=swap"> |
| 9 | + <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous"> |
| 10 | + <link rel="stylesheet" href="/css/reset3.css"> |
| 11 | + <link rel="stylesheet" href="/css/site3.css"> |
| 12 | + <link rel="stylesheet" href="/css/pygments3.css"> |
| 13 | +</head> |
| 14 | +<body> |
| 15 | +<div id="main"> |
| 16 | + |
| 17 | +<div id="banner"> |
| 18 | + <header> |
| 19 | + <nav id="top"> |
| 20 | + <h1 id="breadcrumb"> |
| 21 | + <a class="nav-logo" href="/"><img src="/images/logo-200.png" height="35"></a> <a href="/docs">Documentation</a><span class="sep"> / </span><a href="/docs/getting-started/">Getting started</a><span class="sep"> / </span><span class="last">Maven</span> |
| 22 | + </h1> |
| 23 | + <ul> |
| 24 | + <li> <a href="https://github.com/ebean-orm/website-source/blob/master/docs/getting-started/maven.html"><i class="fab fa-github"></i> edit page</a> |
| 25 | +</li> |
| 26 | + <li><a onclick="toggleTheme();" title="switch dark light theme"><i class="fas fa-adjust"></i></a></li> |
| 27 | + </ul> |
| 28 | + </nav> |
| 29 | + </header> |
| 30 | +</div> |
| 31 | +<div class="grid grid-docs"> |
| 32 | + <aside> |
| 33 | +<nav class="side"> |
| 34 | + <ul> |
| 35 | + <li class="nav0 active"> |
| 36 | + <a class="active" href="/docs/getting-started">Getting started</a> |
| 37 | + <ul> |
| 38 | + <li class="nav1 "> |
| 39 | + <a href="/docs/getting-started/intellij-idea">IntelliJ</a> |
| 40 | + </li> |
| 41 | + <li class="nav1 "> |
| 42 | + <a href="/docs/getting-started/eclipse-ide">Eclipse</a> |
| 43 | + </li> |
| 44 | + <li class="nav1 active"> |
| 45 | + <a class="active" href="/docs/getting-started/maven">Maven</a> |
| 46 | + </li> |
| 47 | + <li class="nav1 "> |
| 48 | + <a href="/docs/getting-started/gradle">Gradle</a> |
| 49 | + </li> |
| 50 | + <li class="nav1 "> |
| 51 | + <a href="/docs/getting-started/ebean-test">Test setup</a> |
| 52 | + </li> |
| 53 | + </ul> |
| 54 | + </li> |
| 55 | + <li class="nav0 "> |
| 56 | + <a href="/docs/intro">Introduction</a> |
| 57 | + </li> |
| 58 | + <li class="nav0 "> |
| 59 | + <a href="/docs">Documentation</a> |
| 60 | + </li> |
| 61 | + <li class="nav0 "> |
| 62 | + <a href="/support">Getting help</a> |
| 63 | + </li> |
| 64 | + <li class="nav0 "> |
| 65 | + <a target="_blank" href="/apidoc/13">API Javadoc</a> |
| 66 | + </li> |
| 67 | + <li class="nav0 "> |
| 68 | + <a href="/videos">Videos</a> |
| 69 | + </li> |
| 70 | + <li class="nav0 "> |
| 71 | + <a href="/docs/upgrading">Upgrading</a> |
| 72 | + </li> |
| 73 | + <li class="nav0 "> |
| 74 | + <a href="/releases">Releases</a> |
| 75 | + </li> |
| 76 | + |
| 77 | + </ul> |
| 78 | +</nav> |
| 79 | + </aside> |
| 80 | + <article> |
| 81 | +<form action="https://www.google.com/search" method="get" class="inline-form"> |
| 82 | + <input type="hidden" name="as_sitesearch" value="ebean.io"> |
| 83 | + <div id="page-search"> |
| 84 | + <div class="input-group"> |
| 85 | + <input class="frm" name="q" id="searchinput" type="text" placeholder="Search... (press 's' to focus)" data-placeholder-focus="Search... (use '↑', '↓' and '⏎' to select results)" data-placeholder-blur="Search... (press 's' to focus)" autocomplete="off"> |
| 86 | + <div class="input-group-btn"> |
| 87 | + <button class="frm" type="submit"><i class="fas fa-search"></i></button> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + <div id="page-search-results" style="display: none;"> |
| 91 | + <ul id="search-results-container" class="search-results"><li class=" active"><a href="/docs" title="Docs"><span style="color:#777;">Docs</span> Documentation </a></li><li class=""><small style="color:#999;">And 101 more...</small></li></ul> |
| 92 | + </div> |
| 93 | + </div> |
| 94 | +</form> |
| 95 | + |
| 96 | + |
| 97 | +<h2 id="dependencies">Main dependency</h2> |
| 98 | +<p> |
| 99 | + Ebean provides a dependency per database platform. We include one |
| 100 | + or more of these dependencies for each database that our application |
| 101 | + is going to use. |
| 102 | +</p> |
| 103 | +<ul> |
| 104 | + <li>io.ebean:ebean-clickhouse</li> |
| 105 | + <li>io.ebean:ebean-cockroach</li> |
| 106 | + <li>io.ebean:ebean-db2</li> |
| 107 | + <li>io.ebean:ebean-hana</li> |
| 108 | + <li>io.ebean:ebean-h2</li> |
| 109 | + <li>io.ebean:ebean-mysql</li> |
| 110 | + <li>io.ebean:ebean-mariadb</li> |
| 111 | + <li>io.ebean:ebean-oracle</li> |
| 112 | + <li>io.ebean:ebean-postgres</li> |
| 113 | + <li>io.ebean:ebean-sqlanywhere</li> |
| 114 | + <li>io.ebean:ebean-sqlite</li> |
| 115 | + <li>io.ebean:ebean-sqlserver</li> |
| 116 | + <li>io.ebean:ebean-yugabyte</li> |
| 117 | +</ul> |
| 118 | +<p> |
| 119 | + For example, if our application is only going to use Postgres then |
| 120 | + we add the <code>io.ebean:ebean-postgres</code> dependency. |
| 121 | +</p> |
| 122 | + |
| 123 | +<div class="syntax xml"><div class="highlight"><pre><span></span><span class="nt"><dependency></span> |
| 124 | + <span class="nt"><groupId></span>io.ebean<span class="nt"></groupId></span> |
| 125 | + <span class="nt"><artifactId></span>ebean-postgres<span class="nt"></artifactId></span> |
| 126 | + <span class="nt"><version></span>14.1.0<span class="nt"></version></span> |
| 127 | +<span class="nt"></dependency></span> |
| 128 | +</pre></div> |
| 129 | +</div> |
| 130 | + |
| 131 | + |
| 132 | +<h2 id="testDependencies">Test Dependencies</h2> |
| 133 | +<p> |
| 134 | + Add <code>io.ebean:ebean-test</code> as a test dependency. |
| 135 | +</p> |
| 136 | +<p> |
| 137 | + This configures Ebean for running tests including automatic use of docker |
| 138 | + containers for Postgres, MySql, Oracle, SqlServer, Hana + support for H2 and SqlLite. |
| 139 | +</p> |
| 140 | +<p> |
| 141 | + Refer to: <a href="/docs/testing">docs / testing</a> |
| 142 | +</p> |
| 143 | +<div class="syntax xml"><div class="highlight"><pre><span></span><span class="c"><!-- Test dependencies --></span> |
| 144 | +<span class="nt"><dependency></span> |
| 145 | + <span class="nt"><groupId></span>io.ebean<span class="nt"></groupId></span> |
| 146 | + <span class="nt"><artifactId></span>ebean-test<span class="nt"></artifactId></span> |
| 147 | + <span class="nt"><version></span>14.1.0<span class="nt"></version></span> |
| 148 | + <span class="nt"><scope></span>test<span class="nt"></scope></span> |
| 149 | +<span class="nt"></dependency></span> |
| 150 | +</pre></div> |
| 151 | +</div> |
| 152 | + |
| 153 | + |
| 154 | +<h2>build / plugins</h2> |
| 155 | +<p> |
| 156 | + In the <code>build / plugins</code> section: |
| 157 | +</p> |
| 158 | +<ol> |
| 159 | + <li>Add the <code>tiles-maven-plugin</code> to perform build time enhancement</li> |
| 160 | + <li>Add or modify the <code>maven-compiler-plugin</code> to register the <em>querybean-generator</em> annotation processor.</li> |
| 161 | +</ol> |
| 162 | + |
| 163 | +<div class="syntax xml"><div class="highlight"><pre><span></span><span class="nt"><build></span> |
| 164 | + <span class="nt"><plugins></span> |
| 165 | + |
| 166 | + <span class="nt"><plugin></span> |
| 167 | + <span class="nt"><groupId></span>io.repaint.maven<span class="nt"></groupId></span> |
| 168 | + <span class="nt"><artifactId></span>tiles-maven-plugin<span class="nt"></artifactId></span> |
| 169 | + <span class="nt"><version></span>2.40<span class="nt"></version></span> |
| 170 | + <span class="nt"><extensions></span>true<span class="nt"></extensions></span> |
| 171 | + <span class="nt"><configuration></span> |
| 172 | + <span class="nt"><tiles></span> |
| 173 | + <span class="c"><!-- other tiles ... --></span> |
| 174 | + <span class="nt"><tile></span>io.ebean.tile:enhancement:14.1.0<span class="nt"></tile></span> |
| 175 | + <span class="nt"></tiles></span> |
| 176 | + <span class="nt"></configuration></span> |
| 177 | + <span class="nt"></plugin></span> |
| 178 | + |
| 179 | + |
| 180 | + <span class="nt"><plugin></span> |
| 181 | + <span class="nt"><groupId></span>org.apache.maven.plugins<span class="nt"></groupId></span> |
| 182 | + <span class="nt"><artifactId></span>maven-compiler-plugin<span class="nt"></artifactId></span> |
| 183 | + <span class="nt"><version></span>3.10.1<span class="nt"></version></span> |
| 184 | + <span class="nt"><configuration></span> |
| 185 | + ... |
| 186 | + <span class="nt"><annotationProcessorPaths></span> |
| 187 | + <span class="nt"><path></span> |
| 188 | + <span class="nt"><groupId></span>io.ebean<span class="nt"></groupId></span> |
| 189 | + <span class="nt"><artifactId></span>querybean-generator<span class="nt"></artifactId></span> |
| 190 | + <span class="nt"><version></span>14.1.0<span class="nt"></version></span> |
| 191 | + <span class="nt"></path></span> |
| 192 | + <span class="c"><!-- other annotation processors --></span> |
| 193 | + <span class="nt"></annotationProcessorPaths></span> |
| 194 | + <span class="nt"></configuration></span> |
| 195 | + <span class="nt"></plugin></span> |
| 196 | + |
| 197 | + |
| 198 | + <span class="nt"></plugins></span> |
| 199 | +<span class="nt"></build></span> |
| 200 | +</pre></div> |
| 201 | +</div> |
| 202 | + |
| 203 | + |
| 204 | +<h3>Maven enhancement tile</h3> |
| 205 | +<p> |
| 206 | + The maven tile above will enhance the code at build time for both <code>src/main</code> |
| 207 | + and <code>src/test</code>. This is simpler than defining the plugin in the traditional (non-tile) |
| 208 | + fashion and is the preferred approach. |
| 209 | +</p> |
| 210 | +<p> |
| 211 | + If you want to specify the maven enhancement plugin in 'normal' non-tile fashion see |
| 212 | + <a href="maven-plugin">maven plugin</a>. |
| 213 | +</p> |
| 214 | + |
| 215 | +<h3>APT - querybean generation</h3> |
| 216 | +<p> |
| 217 | + Note that if there are no other annotation processors (e.g. mapstruct) then instead of |
| 218 | + explicitly registering the <code>querybean-generator</code> with the maven-compiler-plugin |
| 219 | + we can instead just add it as a dependency with provided scope. |
| 220 | +</p> |
| 221 | + |
| 222 | + |
| 223 | +<h3 id="jdbc-dep">JDBC Driver(s)</h3> |
| 224 | +<p> |
| 225 | + Add the dependency for the JDBC Driver(s) you want to use. |
| 226 | +</p> |
| 227 | + |
| 228 | +<h2 id="kotlin-kapt">Kotlin KAPT</h2> |
| 229 | +<p> |
| 230 | + When using Kotlin we need to use KAPT (Kotlin annotation processing) to |
| 231 | + generate Kotlin query beans. |
| 232 | +</p> |
| 233 | +<p> |
| 234 | + The recommended way to do this is via the <a href="https://avaje.io/kotlin-kapt"><code>io.avaje.kapt</code></a> |
| 235 | + maven tiles as this makes it easier to add additional annotation processors |
| 236 | + (like <a href="https://dinject">DInject</a> for dependency injection for example). |
| 237 | +</p> |
| 238 | +<p> |
| 239 | + Add the maven tiles plugin into the <code>build / plugins</code> section of the pom.xml |
| 240 | + with the tiles for: |
| 241 | +</p> |
| 242 | +<div class="syntax xml"><div class="highlight"><pre><span></span><span class="nt"><plugin></span> |
| 243 | + <span class="nt"><groupId></span>io.repaint.maven<span class="nt"></groupId></span> |
| 244 | + <span class="nt"><artifactId></span>tiles-maven-plugin<span class="nt"></artifactId></span> |
| 245 | + <span class="nt"><version></span>2.40<span class="nt"></version></span> |
| 246 | + <span class="nt"><extensions></span>true<span class="nt"></extensions></span> |
| 247 | + <span class="nt"><configuration></span> |
| 248 | + <span class="nt"><tiles></span> |
| 249 | + <span class="nt"><tile></span>io.ebean.tile:enhancement:14.1.0<span class="nt"></tile></span> <span class="c"><!-- ebean enhancement --></span> |
| 250 | + |
| 251 | + <span class="c"><!-- Kotlin + Java compilers with KAPT support --></span> |
| 252 | + <span class="nt"><tile></span>io.avaje.kapt:compile:1.1<span class="nt"></tile></span> |
| 253 | + |
| 254 | + <span class="c"><!-- KAPT query bean generator --></span> |
| 255 | + <span class="nt"><tile></span>io.avaje.kapt:querybean-generator:1.1<span class="nt"></tile></span> |
| 256 | + |
| 257 | + <span class="c"><!-- other annotation processors ... --></span> |
| 258 | + <span class="c"><!-- <tile>io.avaje.kapt:dinject-generator:1.1</tile> --></span> |
| 259 | + <span class="c"><!-- <tile>io.avaje.kapt:javalin-generator:1.1</tile> --></span> |
| 260 | + |
| 261 | + <span class="c"><!-- other tiles ... --></span> |
| 262 | + |
| 263 | + <span class="nt"></tiles></span> |
| 264 | + <span class="nt"></configuration></span> |
| 265 | +<span class="nt"></plugin></span> |
| 266 | +</pre></div> |
| 267 | +</div> |
| 268 | +<p> |
| 269 | + We can add other additional annotation processors by adding tiles, for example: |
| 270 | +</p> |
| 271 | +<ul> |
| 272 | + <li>io.avaje.kapt:dinject-generator:1.1 - for DInject Dependency injection generation</li> |
| 273 | + <li>io.avaje.kapt:javalin-generator:1.1 - for Javalin controller generation</li> |
| 274 | +</ul> |
| 275 | + |
| 276 | +<h3>Example project</h3> |
| 277 | +<p> |
| 278 | + <a href="https://github.com/ebean-orm-examples/example-kotlin/blob/master/pom.xml">Full example pom for Kotlin query bean generation</a> |
| 279 | +</p> |
| 280 | + |
| 281 | + |
| 282 | + |
| 283 | + <nav class="next"> |
| 284 | + <p class="next"> |
| 285 | + <a href="ebean-test" class="btn btn-info">Next: Test setup</a> |
| 286 | + </p> |
| 287 | + </nav> |
| 288 | + |
| 289 | + |
| 290 | + </article> |
| 291 | +</div> |
| 292 | + |
| 293 | +</div> |
| 294 | +<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> |
| 295 | +<script src="/js/site3.js"></script> |
| 296 | +<script src="/js/search3.js"></script> |
| 297 | +<script async src="https://www.googletagmanager.com/gtag/js?id=UA-75181644-1"></script> |
| 298 | +<script> |
| 299 | + window.dataLayer = window.dataLayer || []; |
| 300 | + function gtag(){dataLayer.push(arguments);} |
| 301 | + gtag('js', new Date()); |
| 302 | + gtag('config', 'UA-75181644-1'); |
| 303 | +</script> |
| 304 | +</body> |
| 305 | +</html> |
0 commit comments