我有一个项目,被其他项目用作Ivy依赖项。它的dependencies.xml
包含许多依赖项,基本上分为3类:
第三个依赖类别对我来说很关键。如果我在servlet-api.jar
类路径中不包含javac
,则无法编译项目。但是,如果我在战争类路径中包含该包,那么我就会陷入一种不好的做法,因为服务器运行时(主要是Tomcat,还有Websphere)包含它们自己的servlet-api.jar
。
对于JDBC连接器,我只需要将它们包含在Ant类路径中以便从Bamboo运行单元测试,因为我想用多个数据库重复相同的测试。
这是我当前的dependency.xml片段:
<configurations>
<conf name="test" visibility="public" extends="compile" />
<conf name="compile" visibility="public" extends="runtime" />
<conf name="runtime" visibility="public" />
<conf name="provided" visibility="public" />
<conf name="junit" visibility="public" />
</configurations>
<!-- Build -->
<dependency org="javax.servlet" name="javax.servlet-api" rev="3.0.1" transitive="false" conf="provided->*" />
<dependency org="javax.servlet.jsp" name="javax.servlet.jsp-api" rev="2.3.1" transitive="false" conf="provided->*" />
<dependency org="javax.el" name="javax.el-api" rev="3.0.0" transitive="false" conf="provided->*" />
<dependency org="mysql" name="mysql-connector-java" rev="5.1.38" transitive="false" conf="provided->*" />
<dependency org="ojdbc" name="ojdbc" rev="14" transitive="false" conf="provided->*" />
<dependency org="org.hsqldb" name="hsqldb" rev="2.3.3" transitive="false" conf="provided->*" />
<dependency org="org.postgresql" name="postgresql" rev="9.4.1207" transitive="false" conf="provided->*" />
<dependency org="com.microsoft" name="sqljdbc" rev="4.1" transitive="false" conf="provided->*" />
<dependency org="org.adrianwalker" name="multiline-string" rev="0.1.2" transitive="false" conf="provided->*" />
<!-- Spring -->
<dependency org="org.springframework" name="spring-core" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-aop" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-beans" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-context" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-context-support" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-expression" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-jdbc" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-orm" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-tx" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-web" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-webmvc" rev="4.2.4.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework" name="spring-test" rev="4.2.4.RELEASE" transitive="false" conf="test->*"/>
<dependency org="org.springframework.plugin" name="spring-plugin-core" rev="1.2.0.RELEASE" transitive="false" conf="runtime->*"/>
<dependency org="org.springframework.plugin" name="spring-plugin-metadata" rev="1.2.0.RELEASE" transitive="false" conf="runtime->*"/>
在上面的示例中,com.adrianwalker#multiline-string
仅用于注释解析而不再需要
在我的main-project
中,我最终使用以下任务检索依赖项
<target name="ivy-retrieve">
<ivy:configure override="true" file="${ivy.install.dir}/ivy-settings.xml" />
<ivy:retrieve sync="true" conf="runtime,junit" type="jar,bundle" pattern="${project.local.lib}/[artifact]-[revision].[ext]" />
<eclipse.refreshLocal depth="infinite" resource="/" if:set="eclipse.running" />
</target>
这将正确填充我的WEB-INF/lib
目录以及我需要的所有依赖项(包括spring-test
)但没有已经手动复制到Tomcat类路径的JDBC连接器
好的...
当我将main-project
嵌入derived-project
<dependency org="com.example" name="main-project" rev="${current.version}" transitive="true" conf="runtime->*"/>
并且
<target name="ivy-retrieve-eclipse">
<ivy:configure override="true" file="${ivy.install.dir}/ivy-settings.xml" />
<ivy:retrieve sync="true" conf="runtime,junit" type="jar,bundle" pattern="${project.local.lib}/[artifact]-[revision].[ext]" />
<eclipse.refreshLocal depth="infinite" resource="/" if:set="eclipse.running" />
</target>
结果是我仍然可以下载所有依赖项。
我只需要告诉Ivy下载runtime
的所有依赖项junit
和derived-project
,包括runtime
和junit
依赖项main-project
的常春藤文件。
我该怎么做?我搞砸了什么?
答案 0 :(得分:0)
所以我认为你的主项目是将它的jar发布到存储库中是正确的吗? (使用发布任务?)。
我认为你的问题是你的子构建的依赖声明中的配置映射:
<dependency org="com.example" name="main-project" rev="${current.version}" transitive="true" conf="runtime->*"/>
您声明本地构建的“运行时”配置已映射到主项目模块中列出的所有配置。这就是你得到所有罐子的原因:
conf="runtime->*"
修复很简单:
conf="runtime"
这是:
的简写conf="runtime->runtime"
答案 1 :(得分:0)
之前的设置存在两个问题:
runtime
,它只会将all
重新映射到<configurations>
<conf name="test" visibility="public" extends="compile" />
<conf name="compile" visibility="public" extends="runtime" />
<conf name="runtime" visibility="public" />
<conf name="provided" visibility="public" />
<conf name="junit" visibility="public" />
</configurations>
个配置关于第2点,我在父项目中有以下内容
<configurations>
<conf name="test" visibility="public" extends="compile" />
<conf name="compile" visibility="public" extends="runtime" />
<conf name="runtime" visibility="public" />
<conf name="provided" visibility="public" extends="compile" />
<conf name="junit" visibility="public" extends="provided, test" />
</configurations>
以下儿童项目
<dependencies>
<dependency org="com.acme" name="parent-project" rev="${phoenix.version}" transitive="true" conf="runtime->runtime"/>
<dependency org="com.acme" name="parent-project" rev="${phoenix.version}" transitive="true" conf="compile->compile"/>
<dependency org="com.acme" name="parent-project" rev="${phoenix.version}" transitive="true" conf="provided->provided"/>
<dependency org="com.acme" name="parent-project" rev="${phoenix.version}" transitive="true" conf="junit->junit"/>
<dependency org="com.acme" name="parent-project" rev="${phoenix.version}" transitive="true" conf="test->test"/>
</dependencies>
所以我必须先将子项目与父项对齐。
第二步,虽然可能要避免,但是对于所需的每个配置,多次重新映射父项目的依赖性。也许我可以优化这个,但至少我没有将jdbc jar下载到运行时类路径中
因此儿童依赖变得
(defun foo ()
(send-to-debug-log "Error. Function terminated." (nth 1 (backtrace-frame 2))))