Selecting correct IVY dependency - ant

I have a project that makes use of some third-party libraries. Some of these drag in transitive dependencies that have actually several artifacts in the repository:
module-1.2.jar
module-1.2-sources.jar
module-1.2-tests.jar
My investigations tought me that these seem to be Maven build artifacts that where propagated with a classifier. Now it seems that IVY is well able to handle the sources file but when I declare a dependency like this, it appears that the wrong jar is selected:
<dependency org="acme" module="module" rev="1.2"/>
When I do a resolve in ANT like this
<ivy:resolve conf="${ivy.non.test.confs}" validate="false" refresh="true" />
<ivy:retrieve conf="${ivy.non.test.confs}" pattern="${build.lib}/[conf]/[artifact].[ext]" sync="true" />
it happens that the module-1.2-tests.jar is selected as resolve target and retrieved under the name of the actual jar name (module-1.2.jar in this example).
What am I doing wrong here?

Related

How can I pass a default value via command line when running ant?

<target name="clone-repo" description="Pull code from SCM repository" depends="resolve">
<taskdef resource="org/eclipse/jgit/ant/ant-tasks.properties" classpathref="build.path"/>
<delete dir="${basedir}/omoc_build"/>
<git-clone uri="https://user:******#github.com/sirect/omoc.git" dest="${basedir}/omoc_build" branch="${branch}" />
<zip destfile="${basedir}/devtoolkit/devtoolkit_docker/config.zip" basedir="${basedir}/omoc_build/config" />
I want to run ant command where by default it should clone from main branch
Few things!
To answer your question, you can set the branch property in a properties file, which would be overwritten if you specify on commandline. Include the property file above your target:
<property file="defaults.properties" description="default configuration."/>
in defaults.properties you'll set branch to main and you could overide it with -Dbranch=non-main-branch
That allows you to set a default.
Now for the advice you didn't ask for:
Don't want ant cloning your source. You should have your build system checkout the source and then ant should build the source. You're creating a chicken and egg problem here... build.xml is in source control, and it's checking out source? That's fishy.

Jar searching for Archive by attaching the name linux-x86_64

I am using ant as a build tool and using Ivy for dependency management.
<dependency conf="compile->master;runtime->default" org="org.springframework" name="spring-web" rev="5.1.6.RELEASE"/>
<dependency conf="compile->master;runtime->default" org="io.projectreactor.netty" name="reactor-netty" rev="0.9.6.RELEASE"/>
Now when I give ant build it is failing to find the jar, the problem is it is attaching linux-x86_64.
It is searching for below jar
http://companyRepo:8081/nexus/content/groups/OfficialDevelopment/io/netty/netty-transport-native-epoll/4.1.48.Final/netty-transport-native-epoll-4.1.48.Final-linux-x86_64.jar
Why is it searching for linux-x86_64 ?
I searched and found similar issues but not sure on the solution.
https://github.com/netty/netty/issues/7101
How to build netty-transport-native-epoll-4.0.32.Final-linux-x86_64.jar?
I have no idea about ant but its basically the "classifier". Please check the ant /ivy documentation on how you can specify a classifier
I'm not an Ivy user, but I believe you need to add a dependency for netty-transport-native-epoll with a nested artifact for the classified native libraries. Something like this:
<dependency org="io.netty" name="netty-transport-native-epoll" rev="4.1.48.Final">
<artifact name="netty-transport-native-epoll"/>
<artifact name="netty-transport-native-epoll" e:classifier="linux-x86_64"/>
</dependency>
I usually use https://mvnrepository.com/ to figure out different dependency syntaxes, and the Ivy descriptors are included, but it seems that, unlike Nexus et. al., it does not support searching by classifier.

ojdeploy - ant task compile application

I am trying to use ojdeploy to compile and build an ADF application through an AntTask.
The ojdeploy task works fine when I specify not to compile the project by adding the line
The ojdeploy task is unable to find several jars required to build the application which I have specified.
I can't find any documentation which describe the use of the ojdeploy to compile applications which makes me think that it does not work.
The ant task I have is below. My thoughts are that the ojdeploy task does not have the jars required to build the project on its classpath. I can't see a way to add these jars to the classpath however.
ojdeploy task:
<target name="deploy" description="Deploy JDeveloper profiles">
<property name="status" value="${env.WORKSPACE}/deploy/ojdeploy-statuslog.xml"/>
<taskdef name="ojdeploy"
classname="oracle.jdeveloper.deploy.ant.OJDeployAntTask"
uri="oraclelib:OJDeployAntTask"
classpathref="classpath"/>
<ora:ojdeploy xmlns:ora="oraclelib:OJDeployAntTask"
executable="${env.oracle.middleware}/jdeveloper/jdev/bin/ojdeploy.exe"
failonerror="true"
ora:buildscript="${env.WORKSPACE}/deploy/ojdeploy-build.xml"
ora:statuslog="C:/Oracle/Middleware/ojdeploy-statuslog.xml">
<ora:deploy>
<ora:parameter name="workspace"
value="${env.WORKSPACE}/JWS.jws"/>
<ora:parameter name="profile"
value="*"/>
<!--<ora:parameter name="nocompile" value="true"/>-->
<ora:parameter name="outputfile"
value="${env.WORKSPACE}/deploy/${deployment.profile.name}"/>
</ora:deploy>
</ora:ojdeploy>
</target>
Resolved.
ojdeploy uses the jws and jpr files to find the libraries required. The jpr file was missing several JDeveloper/ADF libraries which JDeveloper is able to resolve.
However for ojdeploy to work ALL the libraries and dependencies are required to be in the jws/jpr file accordingly using the libraries/classpath and dependencies options.

Get maven runtime dependencies in ant

I want to get the set of runtime dependencies from maven in ant. I'm using the maven ant tasks.
I know that you can limit the dependencies by scope (see docs):
<artifact:dependencies filesetId="dependency.fileset" useScope="runtime">
<artifact:pom file="pom.xml" id="myProject" />
</artifact:dependencies>
and that the scope options (from the docs) are:
•compile - Includes scopes compile, system and provided
•runtime - Includes scopes compile and runtime
•test - Includes scopes system, provided, compile, runtime and test
However, I want to get only the runtime dependencies (i.e. exclude compile dependencies). My best idea so far is to get the runtime dependencies and the compile dependencies, and iterate through the runtime dependencies to find those that are not in the compile dependencies, but I haven't yet worked out how to do this.
Any ideas?
You need something along the lines of:
...
<artifact:pom id="maven.project" file="pom.xml"/>
<artifact:dependencies useScope="runtime"
filesetId="dependencies.runtime"
pomRefId="maven.project"
settingsFile="${settings.xml}"/>
...
Then you can use the dependencies.runtime fileset as usual.
I hope this makes more sense.
So this what I tried to get the difference of the runtime and compile file sets (although this makes the assumption that there's nothing in the compile fileset that's not also in the runtime fileset)
<artifact:dependencies filesetId="runtime" scopes="runtime">
<artifact:pom file="pom.xml" id="myProject" />
</artifact:dependencies>
<artifact:dependencies filesetId="compile" scopes="compile">
<artifact:pom file="pom.xml" id="myProject" />
</artifact:dependencies>
<difference id="difference" >
<resources refid="runtime" />
<resources refid="compile" />
</difference>
However, this wasn't producing the results that I expected, so I did the following, and found that the runtime fileset did not contain the compile dependencies.
<echo message="${toString:runtime}" />
<echo message="${toString:compile}" />
So I can just use the runtime scope...

Ant build scripts, antcall, dependencies, etc

I have a build script and as part of that script it copies a jar file to a directory, for ease lets call it the utils jar. the utils jar is built by another build script sitting in another directory. What im trying to do have my build script run the utils build script so that I can ensure the utils jar is up to date.
So I know I need to import the utils build file.
<import file="../utils/build/build.xml" />
Which doesn't work because the import task, unlike almost every other ant taks, doesn't run from basedir, it runs from the pwd. So to get around that I have this little ditty, which does successfully import the build file
<property name="baseDirUpOne" location=".." />
<import file="${baseDirUpOne}/utils/build/build.xml" />
So now that ive solved my import problem I need to call the task, well that should be easy right:
<antcall target="utils.package" />
note that in the above, utils is the project name of ../utils/build/build.xml
the problem I'm now running into is that ant call doesn't execute in ../utils/build so what I need, and cant find, is a runat property or something similar, essentially:
<antcall target="utils.package" runat="../utils/build" />
The reason I need this is that in my utils build file the step to select which code to copy to the jar is based on relative paths so as to avoid hardcoding paths in my ant file. Any ideas?
I've got something similar set up: I have a main Ant build.xml which calls a separate build.xml that takes care of building my tests. This is how I do it:
<target name="build-tests">
<subant target="build">
<fileset dir="${test.home}" includes="build.xml"/>
</subant>
</target>
The trick is to use subant instead of antcall. You don't have to import the other build file.
Try using the "ant" task instead of the "antcall" task, which runs the imported build directly instead of importing it into the current build file. It has a "dir" parameter:
the directory to use as a basedir
for the new Ant project. Defaults to
the current project's basedir, unless
inheritall has been set to false, in
which case it doesn't have a default
value. This will override the basedir
setting of the called project.
So you could do:
<ant antfile="${baseDirUpOne}/utils/build/build.xml" dir="../utils/build" />
or something like that.
You can pass params down to antcall using nested in the antcall block. So, you can pass the properties down that way (probably even basedir since properties are immutable).

Resources