我刚刚使用 apache ant 和 ivy 作为依赖项管理器设置了我的第一个项目。它工作得很好!但我有一件事我无法克服。由于我有几个使用 slf4j 的依赖项,因此存在版本不匹配的冲突。所以我在 ivy.xml 中定义了一个冲突标签来强制某个版本(在本例中为 1.5.6)。使用 Eclipse 插件 IvyIDE 运行 Ivy 解析可以正常工作。但是当使用我的 ant 构建文件来构建我的应用程序时,我得到一个 xml 语法错误:
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: B:\core-lib\build.xml
parsing buildfile B:\core-lib\build.xml with URI = file:/B:/core-lib/build.xml
Project base dir set to: B:\core-lib
parsing buildfile jar:file:/C:/Program%20Files/InformDevTools/eclipse/plugins/org.apache.ant_1.8.2.v20120109-1030/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/InformDevTools/eclipse/plugins/org.apache.ant_1.8.2.v20120109-1030/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `resolve' is [clean, init, resolve]
Complete build sequence is [clean, init, resolve, compile, resources, test, dist, ]
clean:
[delete] Deleting directory B:\core-lib\build
[delete] Deleting directory B:\core-lib\build\lib
[delete] Deleting directory B:\core-lib\build\main
[delete] Deleting directory B:\core-lib\build\report\test
[delete] Deleting directory B:\core-lib\build\report
[delete] Deleting directory B:\core-lib\build\test
[delete] Deleting directory B:\core-lib\build
[delete] Deleting directory B:\core-lib\dist
[delete] Deleting directory B:\core-lib\dist
init:
Override ignored for property "DSTAMP"
Override ignored for property "TSTAMP"
Override ignored for property "TODAY"
[mkdir] Created dir: B:\core-lib\build
[mkdir] Created dir: B:\core-lib\build\main
[mkdir] Created dir: B:\core-lib\build\lib
[mkdir] Created dir: B:\core-lib\dist
[mkdir] Created dir: B:\core-lib\build\test
[mkdir] Created dir: B:\core-lib\build\report\test
resolve:
parsing buildfile jar:file:/C:/Users/admin/.eclipse/org.eclipse.platform_3.7.0_1992851616/plugins/org.apache.ivy.eclipse.ant_2.3.0.cr120120416000235/ivy.jar!/org/apache/ivy/ant/antlib.xml with URI = jar:file:/C:/Users/admin/.eclipse/org.eclipse.platform_3.7.0_1992851616/plugins/org.apache.ivy.eclipse.ant_2.3.0.cr120120416000235/ivy.jar!/org/apache/ivy/ant/antlib.xml from a zip file
[ivy:retrieve] No ivy:settings found for the default reference 'ivy.instance'. A default instance will be used
[ivy:retrieve] Loading jar:file:/C:/Users/admin/.eclipse/org.eclipse.platform_3.7.0_1992851616/plugins/org.apache.ivy.eclipse.ant_2.3.0.cr120120416000235/ivy.jar!/org/apache/ivy/core/settings/ivy.properties
[ivy:retrieve] searching settings file: trying B:\core-lib\ivysettings.xml
[ivy:retrieve] :: Apache Ivy 2.3.0-rc1 - 20120416000235 :: http://ant.apache.org/ivy/ ::
[ivy:retrieve] jakarta commons httpclient not found: using jdk url handling
[ivy:retrieve] :: loading settings :: file = B:\core-lib\ivysettings.xml
[ivy:retrieve] no default ivy user dir defined: set to C:\Users\admin\.ivy2
[ivy:retrieve] no default cache defined: set to C:\Users\admin\.ivy2\cache
[ivy:retrieve] settings loaded (31ms)
[ivy:retrieve] default cache: C:\Users\admin\.ivy2\cache
[ivy:retrieve] default resolver: inform-artifactory
[ivy:retrieve] -- 5 resolvers:
[ivy:retrieve] inform [release] [ibiblio]
[ivy:retrieve] inform [snapshot] [ibiblio]
[ivy:retrieve] inform [proxied] [ibiblio]
[ivy:retrieve] inform-artifactory [chain] [inform [proxied], inform [third-party], inform [release], inform [snapshot]]
[ivy:retrieve] inform [third-party] [ibiblio]
[ivy:retrieve] no resolved descriptor found: launching default resolve
Overriding previous definition of property "ivy.version"
[ivy:retrieve] using ivy parser to parse file:/B:/core-lib/ivy.xml
[ivy:retrieve] [xml parsing: ivy.xml:28:108: cvc-complex-type.2.4.a: Ungültiger Content wurde beginnend mit Element "dependency" gefunden. "{conflict}" wird erwartet. in file:/B:/core-lib/ivy.xml
[ivy:retrieve] ]
BUILD FAILED
B:\core-lib\build.xml:77: syntax errors in ivy file: java.text.ParseException: [xml parsing: ivy.xml:28:108: cvc-complex-type.2.4.a: Ungültiger Content wurde beginnend mit Element "dependency" gefunden. "{conflict}" wird erwartet. in file:/B:/core-lib/ivy.xml
]
at org.apache.ivy.ant.IvyResolve.doExecute(IvyResolve.java:396)
at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:277)
at org.apache.ivy.ant.IvyPostResolveTask.ensureResolved(IvyPostResolveTask.java:231)
at org.apache.ivy.ant.IvyPostResolveTask.prepareAndCheck(IvyPostResolveTask.java:178)
at org.apache.ivy.ant.IvyRetrieve.doExecute(IvyRetrieve.java:87)
at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:277)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
Caused by: java.text.ParseException: [xml parsing: ivy.xml:28:108: cvc-complex-type.2.4.a: Ungültiger Content wurde beginnend mit Element "dependency" gefunden. "{conflict}" wird erwartet. in file:/B:/core-lib/ivy.xml
]
at org.apache.ivy.plugins.parser.AbstractModuleDescriptorParser$AbstractParser.checkErrors(AbstractModuleDescriptorParser.java:89)
at org.apache.ivy.plugins.parser.AbstractModuleDescriptorParser$AbstractParser.getModuleDescriptor(AbstractModuleDescriptorParser.java:344)
at org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser.parseDescriptor(XmlModuleDescriptorParser.java:117)
at org.apache.ivy.plugins.parser.AbstractModuleDescriptorParser.parseDescriptor(AbstractModuleDescriptorParser.java:48)
at org.apache.ivy.core.resolve.ResolveEngine.resolve(ResolveEngine.java:184)
at org.apache.ivy.Ivy.resolve(Ivy.java:503)
at org.apache.ivy.ant.IvyResolve.doExecute(IvyResolve.java:326)
... 20 more
Total time: 500 milliseconds
如果我删除冲突定义,构建将按预期工作。这是 ivy.xml:
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="eu.inform" module="isac3-core" revision="1.0-snapshot"></info>
<configurations>
<conf name="build" description="provide business logic for isac3"/>
<conf name="test" extends="build" visibility="private" description="just for JUnit testing"/>
</configurations>
<publications>
<artifact name="core-lib" type="jar" conf="build" ext="jar"/>
</publications>
<dependencies>
<dependency org="org.apache.commons" name="commons-lang3" rev="3.1" conf="build->default"/>
<dependency org="commons-codec" name="commons-codec" rev="1.6" conf="build->default"/>
<dependency org="org.apache.mina" name="mina-core" rev="2.0.4" conf="build->default"/>
<dependency org="org.apache.tika" name="tika-app" rev="1.1" conf="build->default"/>
<!--
Resolve conflict for SLF4J by selecting the latest compatible version:
Apache tika comes packaged with slf4j 1.5.6, so we cannot exclude this dependency because it is part of the jar.
Hibernate specifies a dependency to slf4j 1.6.1 by maven pom file.
-->
<conflict org="org.slf4j" rev="1.5.6"/>
<dependency org="org.springframework" name="spring-aop" rev="3.1.1.RELEASE" conf="build->default"/>
<dependency org="org.aspectj" name="aspectjweaver" rev="1.5.4" conf="build->default"/>
<dependency org="org.springframework" name="spring-orm" rev="3.1.1.RELEASE" conf="build->default">
<!-- don't include any ORM implementation since we defined the one we use -->
<exclude org="org.eclipse.persistence" />
<exclude org="toplink.essentials" />
<exclude org="org.apache.ibatis" />
<exclude org="org.apache.openjpa" />
<exclude org="org.hibernate" />
</dependency>
<dependency org="org.hibernate" name="hibernate-core" rev="4.1.4.Final" conf="build->default"/>
<dependency org="org.hibernate" name="hibernate-ehcache" rev="4.1.4.Final" conf="build->default"/>
<dependency org="org.hibernate" name="hibernate-envers" rev="4.1.4.Final" conf="build->default"/>
<dependency org="org.hibernate" name="hibernate-search-engine" rev="4.1.1.Final" conf="build->default"/>
<dependency org="org.hibernate" name="hibernate-search-orm" rev="4.1.1.Final" conf="build->default"/>
<dependency org="c3p0" name="c3p0" rev="0.9.1.2" conf="build->default"/>
<dependency org="de.jollyday" name="jollyday" rev="0.4.6" conf="build->default"/>
<dependency org="log4j" name="log4j" rev="1.2.17" conf="build->default"/>
<!-- JDBC drivers -->
<dependency org="net.sourceforge.jtds" name="jtds" rev="1.2.4" conf="build->default"/>
<dependency org="com.microsoft" name="sqljdbc4" rev="4.0" conf="build->default"/>
<dependency org="com.oracle" name="ojdbc6" rev="11.2.0.3" conf="build->default"/>
<!-- dependencies solely for testing purposes (none-deployed) -->
<dependency org="junit" name="junit" rev="4.10" conf="test->default"/>
</dependencies>
这就是 ant build.xml(我省略了不必要的行以使其更紧凑):
<?xml version="1.0" encoding="ISO-8859-1"?>
<property name="src_base" location="src/main" />
<property name="src" location="${src_base}/java" />
<property name="config" location="${src_base}/config" />
<property name="resource" location="${src_base}/resource" />
<property name="build" location="build" />
<property name="buildSrc" location="${build}/main" />
<property name="lib" location="${build}/lib" />
<property name="dist" location="dist" />
<property name="distName" value="isac3-core-lib" />
<property name="distFileName" value="${distName}-${build.timestamp}.jar" />
<property name="zipFileName" value="${distName}-${build.timestamp}.zip" />
<property name="test.src" location="src/test/java" />
<property name="test.build" location="build/test" />
<property name="test.reports" location="build/report/test" />
<property name="ant.build.javac.source" value="1.7" />
<!-- Source-level version number -->
<property name="ant.build.javac.target" value="1.7" />
<!-- Class-compatibility version number -->
<property name="build.compiler" value="modern" />
...
<!-- =================================
target: init
================================= -->
<target name="init" depends="clean">
<!-- Create the time stamp -->
<tstamp />
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}" />
<mkdir dir="${buildSrc}" />
<mkdir dir="${lib}" />
<mkdir dir="${dist}" />
<mkdir dir="${test.build}" />
<mkdir dir="${test.reports}" />
</target>
<!-- =================================
target: resolve
================================= -->
<target name="resolve" depends="init" description="retrieve dependencies with ivy">
<ivy:retrieve pattern="${lib}/[conf]/[artifact].[ext]" />
</target>
...
错误发生在 ant 目标“解决”中。常春藤似乎已加载,设置文件也按预期使用。但正如已经提到的,我得到了那个语法错误。
有没有人见过这个,可以给我一个提示?
问候,
塞巴斯蒂安