[英]Mitigating verbosity of Maven pom.xml files (or: a critique of Maven by a fan)
我喜歡maven。 我非常喜歡它。 自從我從Ant切換到它以來,我已經節省了大量的工作時間,構建構建文件,管理依賴項等,並在我的源代碼控制存儲庫中節省了大量空間。
問題是maven文件太冗長了。 並不是說Ant文件不那么冗長,但它們的冗長程度適合他們的工作。
例如, 而不是寫 :
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<dependency>
<groupId>com.myosproject</groupId>
<artifactId>superlibrary</artifactId>
<version>7.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
我想寫點類似的東西
<dependencies>
commons-logging/commons-logging/1.1.1
com.myosproject/superlibrary/7.5
test:junit/junit/3.8.1
</dependencies>
或者代替
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
我想要
<build version="1.5"/>
並且(最后一個例子,我們已經完成), 而不是寫 :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native2ascii-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>native2ascii</goal>
</goals>
<configuration>
<encoding>UTF8</encoding>
</configuration>
</execution>
</executions>
</plugin>
我不想寫任何東西。 即,maven將檢測native2ascii文件夾的存在,並默認做正確的事情 。
我知道我正在將內置功能與插件和其他東西混合使用,但請嘗試從對該工具非常滿意的maven用戶的角度來看,但認為他可以更開心。
所以:
有沒有辦法讓maven像這樣工作? (這樣做是否明智)
是否有另一種我不知道的工具呢?
Maven配置肯定是冗長的,Maven 3旨在解決這個問題(參見這些視頻的一些想法),並且有一個Maven 2插件允許在YAML中定義配置。 還有一個實驗性的“簡潔”分支 ,它支持屬性,在某種程度上減少了配置的大小。
例如:
groupId: org.twdata.maven
artifactId: maven-yamlpom-plugin
version: 1.0-SNAPSHOT
packaging: maven-plugin
name: YAML POM Plugin
dependencies:
- { groupId: org.apache.maven, artifactId: maven-plugin-api, version: 2.0 }
- { groupId: SnakeYAML, artifactId: SnakeYAML, version: 1.1 }
- { groupId: commons-io, artifactId: commons-io, version: 1.4 }
- { groupId: dom4j, artifactId: dom4j, version: 1.4 }
- { groupId: junit, artifactId: junit, version: 3.8.1, scope: test }
- { groupId: xmlunit, artifactId: xmlunit, version: 1.2, scope: test }
build:
plugins:
- artifactId: maven-compiler-plugin
configuration:
source: 1.5
target: 1.5
repositories:
- id: snakeyaml
name: SnakeYAML repository
url: http://snakeyamlrepo.appspot.com/repository
使用Maven 2,您可以通過在父項目中定義公共配置來緩解詳細程度,在您引用的示例中,依賴項都可以在父項中定義,或者在父項的dependencyManagement部分中定義,以便子項可以聲明junit依賴項如
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
這有點改善。
插件既可以在父級中聲明,也不需要在子級中定義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.