jeg har så vondt i mvn javabin, 10. mars, 2011 johannes brodwall
TRANSCRIPT
Jeg har så vondt i mvn
JavaBin, 10. mars, 2011
Johannes Brodwall
mvn intro
mvn introarchetype:generate
test – package – install – deploy
eclipse:eclipse/idea:idea
$ mvn archetype:generate
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[hoose archetype:
….
[hoose archetype:
1: remote -> docbkx-quickstart-archetype (-)
2: remote -> multi (-)
3: remote -> simple (-)
...
101: remote -> maven-archetype-quickstart (An archetype which contains a sample Maven project.)
...
375: remote -> javg-minimal-archetype (-)
Choose a number: 101: 101
Choose version:
... 6: 1.1
Choose a number: 6:
Define value for property 'groupId': : no.steria.demo
Define value for property 'artifactId': : maven-demo
Define value for property 'version': 1.0-SNAPSHOT:
Define value for property 'package': no.steria.demo:
Confirm properties configuration:
groupId: no.steria.demo
artifactId: maven-demo
version: 1.0-SNAPSHOT
package: no.steria.demo
Y:
[INFO] project created from Old (1.x) Archetype in dir: C:\Users\johannes\workspace\tmp\maven-demo
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20 seconds
[INFO] Finished at: Thu Mar 10 08:42:16 CET 2011
[INFO] Final Memory: 19M/154M
[INFO] ------------------------------------------------------------------------
/** * Unit test for simple App. */public class AppTest extends TestCase{ /** * Create the test case * * @param testName name of the test case */ public AppTest( String testName ) { super( testName ); }
/** * @return the suite of tests being tested */ public static Test suite() { return new TestSuite( AppTest.class ); }
/** * Rigourous Test :-) */ public void testApp() { assertTrue( true ); }}
mvn introarchetype:generate
test – package – install – deploy
eclipse:eclipse/idea:idea
mvn introarchetype:generate
test – package – install – deploy
eclipse:eclipse/idea:idea
$ mvn deploy[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-demo
[INFO] task-segment: [deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] [compiler:compile {execution: default-compile}]
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] [surefire:test {execution: default-test}]
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running no.steria.demo.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.029 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
compile
test-compile
test
[INFO] [jar:jar {execution: default-jar}]
[INFO] [install:install {execution: default-install}]
[INFO] Installing ...\maven-demo\target\maven-demo-1.0-SNAPSHOT.jar to
$HOME\.m2\repository\ no\steria\demo\maven-demo\ 1.0-SNAPSHOT\maven-demo-1.0-SNAPSHOT.jar
[INFO] [deploy:deploy {execution: default-deploy}]
Uploading: scp:[email protected]:.../maven-demo-1.0-20110310.075455-2.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Thu Mar 10 08:54:56 CET 2011
[INFO] Final Memory: 19M/154M
[INFO] ------------------------------------------------------------------------
package
install
deploy
mvn introarchetype:generate
test – package – install – deploy
eclipse:eclipse/idea:idea
mvn introarchetype:generate
test – package – install – deploy
eclipse:eclipse/idea:idea
$ mvn eclipse:eclipse[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'eclipse'.
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-demo
[INFO] task-segment: [eclipse:eclipse]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing eclipse:eclipse
[INFO] No goals needed for project - skipping
[INFO] [eclipse:eclipse {execution: default-cli}]
[INFO] Using Eclipse Workspace: C:\Users\johannes\workspace
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "maven-demo" to C:\Users\johannes\workspace\tmp\maven-demo.
[INFO]
Sources for some artifacts are not available.
Please run the same goal with the -DdownloadSources=true parameter in order to check remote repositories for sour
ces.
List of artifacts without a source archive:
o junit:junit:3.8.1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu Mar 10 09:02:56 CET 2011
[INFO] Final Memory: 15M/155M
[INFO] ------------------------------------------------------------------------
-DdownloadSources
mvn basicsSNAPSHOT vs release-versions
repositories
modules
Jeg har så vondt i mvn
Jeg har så vondt i mvn
Transitive dependencies
Fragmenterte prosjekter
Plugin overbruk
Dependency nightmare
$ mvn dependency:tree[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-demo
[INFO] task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] no.steria.demo:maven-demo:jar:1.0-SNAPSHOT
[INFO] \- commons-logging:commons-logging:jar:1.1:compile
[INFO] +- log4j:log4j:jar:1.2.12:compile
[INFO] +- logkit:logkit:jar:1.0.1:compile
[INFO] +- avalon-framework:avalon-framework:jar:4.1.3:compile
[INFO] \- javax.servlet:servlet-api:jar:2.3:compile
Servlet-api!?!!
<dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1</version> <type>jar</type> <scope>compile</scope> <exclusions> <exclusion> <artifactId>servlet-api</artifactId> <groupId>javax.servlet</groupId> </exclusion> </exclusions></dependency>
“And Maven brought forth a Plague of Apache commons,
and there was a flood of all the Libraries of the Internet as a Judgment upon the people”
-Dan North, QCon London 2010
\- net.sourceforge.htmlunit:htmlunit:jar:2.8:compile
+- xalan:xalan:jar:2.7.1:compile
| \- xalan:serializer:jar:2.7.1:compile
+- commons-collections:commons-collections:jar:3.2.1:compile
+- commons-lang:commons-lang:jar:2.4:compile
+- org.apache.httpcomponents:httpclient:jar:4.0.1:compile
| \- org.apache.httpcomponents:httpcore:jar:4.0.1:compile
+- org.apache.httpcomponents:httpmime:jar:4.0.1:compile
| \- org.apache.james:apache-mime4j:jar:0.6:compile
+- commons-codec:commons-codec:jar:1.4:compile
+- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.8:compile
+- xerces:xercesImpl:jar:2.9.1:compile
| \- xml-apis:xml-apis:jar:1.3.04:compile
+- net.sourceforge.nekohtml:nekohtml:jar:1.9.14:compile
+- net.sourceforge.cssparser:cssparser:jar:0.9.5:compile
| \- org.w3c.css:sac:jar:1.3:compile
+- commons-io:commons-io:jar:1.4:compile
\- commons-logging:commons-logging:jar:1.1.1:compile
Xerces
Xalan? Hmm...
Én metode fra commons-lang
Commons-logging….
Og én fra commons-io
Én fra commons-coll
Dependency nightmare
Excludes
Vote with your feet
Make it better: Avoid reuse
Fragmenterte prosjekter
\- org.eclipse.jetty:jetty-plus:jar:8.0.0.M2:compile
+- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
+- org.eclipse.jetty:jetty-webapp:jar:8.0.0.M2:compile
| +- org.eclipse.jetty:jetty-xml:jar:8.0.0.M2:compile
| | \- org.eclipse.jetty:jetty-util:jar:8.0.0.M2:compile
| \- org.eclipse.jetty:jetty-servlet:jar:8.0.0.M2:compile
| \- org.eclipse.jetty:jetty-security:jar:8.0.0.M2:compile
| \- org.eclipse.jetty:jetty-server:jar:8.0.0.M2:compile
| +- org.mortbay.jetty:servlet-api:jar:3.0.20100224:compile
| +- org.eclipse.jetty:jetty-continuation:jar:8.0.0.M2:compile
| \- org.eclipse.jetty:jetty-http:jar:8.0.0.M2:compile
| \- org.eclipse.jetty:jetty-io:jar:8.0.0.M2:compile
\- org.eclipse.jetty:jetty-jndi:jar:8.0.0.M2:compile
\- javax.mail:mail:jar:1.4.1:compile
12 moduler? Virkelig?
mvn-release-plugin
liker ikke SNAPSHOTs
Hvor ligger PersonDAO?
no.steria.person?
no.steria.dao?
Konsistens?
Koherens?
\- org.eclipse.jetty:jetty-plus:jar:8.0.0.M2:compile
+- org.eclipse.jetty:jetty-webapp:jar:8.0.0.M2:compile
\- org.eclipse.jetty:jetty-servlet:jar:8.0.0.M2:compile
\- org.eclipse.jetty:jetty-server:jar:8.0.0.M2:compile
\- org.eclipse.jetty:jetty-http:jar:8.0.0.M2:compile
\- org.eclipse.jetty:jetty-io:jar:8.0.0.M2:compile
Eksempel: Du skal lage støtte for NIO. Hvor?
Når splitter du prosjekter?
Kun for deployment-behov!
Kun for deployment-behov!
\- no.steria.demo:demo-server-package:jar +- no.steria.demo:demo-web:war +- no.steria.demo:demo-core:jar \- no.steria.demo:demo-client:jar \- no.steria.demo:demo-core:jar (duplikat)
Fragmenterte prosjekter
Koherens > Konsistens
Unngå å splitte
Deployment kan kreve splitt
Plugins
Plugins
Java > Mvn plugins
antrun-plugin
Main-klasser
<plugins> <plugin> <groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId> <version>6.1.10</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <stopKey>foo</stopKey> <stopPort>9999</stopPort> </configuration> <executions> <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> <configuration> <scanIntervalSeconds>0</scanIntervalSeconds> <daemon>true</daemon> </configuration> </execution> <execution> <id>stop-jetty</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin>
Portnummer?
Jetty versjon?
Data sources?
Debugging?
Flere kontekster?
Integrasjon med tester?
import org.eclipse.jetty.plus.jndi.EnvEntry;import org.eclipse.jetty.server.Server;import org.eclipse.jetty.webapp.WebAppContext;
…
new EnvEntry(jndiDataSource, dataSource);Server server = new Server(0);server.setHandler( new WebAppContext("src/main/webapp", "/myapp"));server.start();
int localPort = server.getConnectors()[0].getLocalPort();
int localPort = server.getConnectors()[0].getLocalPort();String baseUrl = "http://localhost:" + localPort + "/";
WebDriver browser = createWebDriver();browser.get(baseUrl);browser.findElement( By.linkText("Create person")).click();browser.findElement( By.name("first_name")).sendKeys("Darth");browser.findElement( By.name("last_name")).sendKeys("Vader");browser.findElement( By.name("createPerson")).click();
<plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <configuration> <tasks> <property name="compile_classpath" refid="maven.compile.classpath" /> <java classname="fitnesse.Shutdown" fork="true"> <arg line="-p ${fitnesse.port}" /> <classpath> <pathelement path="${compile_classpath}" /> </classpath> </java> <java classname="fitnesseMain.FitNesseMain" fork="true" spawn="${fitnesse.spawn}"> <arg line="-p ${fitnesse.port}" /> <classpath> <pathelement path="${compile_classpath}" /> </classpath> </java> </tasks> </configuration> </execution> </executions></plugin>
<property name=“mvn_cp" refid="maven.compile.classpath" /><java classname="fitnesseMain.FitNesseMain" fork="true" spawn="true"> <arg line="-p ${fitnesse.port}" /> <classpath> <pathelement path="${mvn_cp}" /> </classpath></java>
Plugins
Java > Mvn plugins
antrun-plugin
Main-klasser
Oppsummering
Oppsummering
Den som spiser pølsemat (transitive deps)
og kjøttmat (fragmenterte prosjekt)
hele dagen
Han blir så doven og så lat
og får så vondt i mvn
Oppsummering
Meeeeen…
den som spiser gullerøtter (excludes)
knekkebrød (dependency:tree)
og peppernøtter (koherens),
tyttebær (mvn-antrun-plugin)
og bjørnebær (main klasser)
og kålrot (sammenhengende moduler)
og persille (Java-kode)
han blir så passe mett i magen,
glad og lystig hele dagen
og så lett i bena at han nesten ikke kan stå stille.
Takk for oppmerksomheten
http://johannesbrodwall.com
http://sterkblanding.no
twitter.com/jhannes