I'm creating a build environment for third party developers. I want to provide them with an ivy.xml which a 3rd party shouldn't change and also a ivy-custom.xml which they should change.
<target name="resolve" depends="download-ivy">
<ivy:resolve file="ivy.xml"/>
<ivy:resolve file="ivy-custom.xml"/>
</target>
This doesn't seem to work, though. The ivy-custom.xml seems to usurp the original ivy.xml. Does anyone know of a way to do this? Thanks.
You may consider split it into 2 separate modules. The first one is with dependency of your ivy.xml and publish it into your maven repository. (said org="com.abc", name="your-module", version 1.0)
Then you may let your 3rd party developers use ivy-custom.xml that also resolve "your-module" as one of the dependency.
<dependency org="com.abc" name="your-module" rev="1.0" transitive="true"/>
This assume your developer have access to your repository.
Related
Goal
I'm trying to make my maven project use the IntelliJ builder when I'm editing code because the IDE offers fast rebuild and hot deployment features that could speed up my work. However I'm running into a roadblock due to how my maven project is set up.
Constraints
I have to use maven the way it's being used. The solution must be in IntelliJ
Note that creating an IntelliJ plugin is an option. I realize this may be necessary due to the limitations of IntelliJ build configuration.
The problem
My project depends on 2 libraries, SharedLibA and SharedLibB, which contain package com.shared. SharedLibA is a new library, and sharedLibB is and old legacy one. SharedLibA and SharedLibB contain packages that are not contained in the other, which are needed by my project. The package they both have, com.shared is needed by the project too. However SharedLibB is legacy/old so we always want Tomcat to prioritize the implementation of classes in com.shared from SharedLibA, not the implementations of those classes in SharedLibB. We accomplish this by having a maven goal that extracts classes under package com.shared from SharedLibA to WEB-INF/classes when the WAR is packaged.
When I try to build my project in IntelliJ, it picks up the wrong implementation of classes in com.shared.* and spews out compilation errors despite compilation working perfectly via maven. I'm stuck with this inflexible maven hackjob but I still want to find a way to make IntelliJ understand that I want SharedLibA's com.shared.* classes to be used in compilation not SharedLibB's. I can't remove SharedLibB from consideration because I need the other classes in SharedLibB to compile my project.
Desired Solution
I'm looking for some kind of logic like "when com.shared.* classes are considered, choose SharedLibA" or "when any package conflict happens in classpath resolution, prioritize ShareLibA" because I'm pretty sure SharedLibA should be prioritized in any package conflict.
Thanks
I hope that explains it well enough, thank you in advance to anyone who chimes in here.
IDE builds the classpath and buildpath based on the dependencies which are configured for the module. It also considers their order - the 1st dependency that match given class will be used.
For Maven-based projects the dependencies list and their order IDE takes from the Maven pom.xml file of the module. So you can set the order in pom.xml file.
Another mentioned option is to exclude the library items. But the better solution would be to configure Maven build properly.
You should try to go to your project ".IML" file and there :
you can create or modify a module.
In there you can include or exclude the libs or defining its use priority
you could use this snippet to inspire
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="8">
<component name="SharedB" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
...
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
...
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
...
</component>
</module>
if you are not confortable with this solution you could use the module settings of Intellij
https://www.jetbrains.com/help/idea/library.html#excluded_lib_items
I'm trying to create a java test to check the status of cron jobs on a kubernetes, however I'm having trouble with the fabric8 imports.
I've tried
import io.fabric8.kubernetes.api.model.batch.Job;
import io.fabric8.kubernetes.api.model.batch.JobList;
However this throws an error. For some reason, java cannot resolve the 'batch' symbol. This tells me there is probably something missing in my ivy.xml dependencies.
I have the following dependencies already in my ivy.xml
<dependency org="io.fabric8" name="kubernetes-client" rev="3.1.12"/>
<dependency org="io.fabric8" name="kubernetes-api" rev="2.0.9"/>
<dependency org="io.fabric8" name="kubernetes-model" rev="3.1.12"/>
Am I missing a dependency? Or is there another problem?
The problem was the dependencies were out of date.
The dependency for JobList wasn't added until several versions later. Apparently, nobody on our team has updated those dependencies in our ivy file for almost a year.
In other words, to avoid issues like this, one should always keep there dependencies up to date.
We have a simple Ivy repository we host off of an in-house server (Apache httpd serving up JARs and their XML Ivy descriptors).
I now have a need to programmatically determine what the latest version of a dependency is in our repo. Thus if we have two versions of Mockito, our repo might look like:
mockito/ ==> organisation
mockito-all ==> module
1.9.4/ ==> revision #
mockito-all-1.9.4.jar
mockito-all-1.9.4-ivy.xml
1.9.5/
mockito-all-1.9.5.jar
mockito-all-1.9.5-ivy.xml
It would be nice if, from Java, I can use Ivy to determine that "1.9.5" is the latest version of the mockito/mockito-all module that we have.
This would likely not be an Ant task, and instead would likely be some custom Java code using the classes that exist inside ivy.jar.
Any ideas? Thanks in advance!
I believe you can use latest.integration revision value to specify the absolute latest version needed. For example, specify your Ivy dependency like so:
<dependency org="mockito" name="mockito-all" rev="latest.integration" />
You can also specify latest.milestone or latest.release if you don't want the "edge" version. Here is a good explanation on the rev value: http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependency.html
So I found your question looking to do the same thing and after some research found that in Ivy 2.4, such a thing exists.
http://ant.apache.org/ivy/history/latest-milestone/use/checkdepsupdate.html
Here is a sample step:
<target name="ivy.outdated" description="Check ivy for outdated jars">
<ivy:resolve/>
<ivy:checkdepsupdate showTransitive="false" revisionToCheck="latest.release"/>
</target>
i need help using IVY as dependencies manager
my application need to load plug-ins at RUN-TIME
means while the core application is running ,user can request for a new plug-in
and install them ,
i wish to manage all installed plug-ins using the core application DB.
i want to get a pom from my plug-ins server (or some other descriptor),
and ask IVY to tell me what are the dependencies OR let IVY
install the plug-in and dependencies ,
based on the current state of my application.
( what do i have right now ,
1.jar's used by core application
2.jar's used by current installed plug-ins)
i wish for each plug-in to have independent directory
under some folder where my application is located (not a shared one)
the thing is i don't know where to start
i notice that there is no programming API for that
i located one link over the network of someone who try something similar
but look likes the code is not completed , or some variable are missing
and i dont know how to complete the rest cause lake of programming documentation
http://www.mail-archive.com/ivy-user#ant.apache.org/msg03228.html
(where the variable "art" came for.....)
can you help me please ...
Thank you all
UPDATE
ok this what i am trying now .
i am getting some a error plus i dont know how to define my archiva server
IvySettings settings = new IvySettings();
settings.setDefaultIvyUserDir(new File("D:/programming/eclipse_projects/ivyTest/repo/"));
settings.setDefaultCache(new File("D:/programming/eclipse_projects/ivyTest/repo/cache/"));
settings.setDefaultCacheArtifactPattern("[module]/[revision]/[module]-[revision](-[classifier]");
Ivy ivy = Ivy.newInstance(settings);
ivy.getLoggerEngine().pushLogger(new DefaultMessageLogger(Message.MSG_VERBOSE));
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), new File("src/movies.pom").toURL(), true);
RetrieveOptions retriveOptions = new RetrieveOptions();
retriveOptions.setUseOrigin(true);
retriveOptions.setConfs(md.getConfigurationsNames());
ivy.retrieve(md.getModuleRevisionId(), "lib/[conf]/[artifact].[ext]", etriveOptions);
this is the error i get
:: loading settings :: url = jar:file:/D:/programming/eclipse_projects/ivyTest/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: retrieving :: org.jtpc#movies
checkUpToDate=true
confs: [default, master, compile, provided, runtime, test, system, sources, javadoc, optional]
java.lang.RuntimeException: problem during retrieve of org.jtpc#movies: java.lang.IllegalStateException: Report file 'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml' does not exist.
at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:206)
at org.apache.ivy.Ivy.retrieve(Ivy.java:540)
at Test.main(Test.java:52)
Caused by: java.lang.IllegalStateException: Report file 'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml' does not exist.
at org.apache.ivy.plugins.report.XmlReportParser.parse(XmlReportParser.java:294)
at org.apache.ivy.core.retrieve.RetrieveEngine.determineArtifactsToCopy(RetrieveEngine.java:288)
at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:104)
... 2 more
Ivy can be used as a standalone java program:
java -jar ivy.jar -retrieve "lib/[conf]/[artifact].[ext]"
The retrieve pattern can be then used to determine where files are installed, based on the ivy configuration settings
$ find lib -type f
lib/core/commons-lang.jar
lib/plugin1/commons-logging.jar
lib/plugin1/commons-codec.jar
lib/plugin2/commons-logging.jar
lib/plugin2/commons-cli.jar
lib/plugin3/commons-logging.jar
Configurations are used as a collective label or grouping of dependencies. They are similar to Maven scopes but much more flexible:
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="core" description="Core application dependencies"/>
<conf name="plugin1" description="Plugin 1 dependencies"/>
<conf name="plugin2" description="Plugin 2 dependencies"/>
<conf name="plugin3" description="Plugin 3 dependencies"/>
</configurations>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.5" conf="core->default"/>
<dependency org="commons-codec" name="commons-codec" rev="1.4" conf="plugin1->default"/>
<dependency org="commons-cli" name="commons-cli" rev="1.2" conf="plugin2->default"/>
<dependency org="commons-logging" name="commons-logging" rev="1.1.1" conf="plugin1,plugin2,plugin3->default"/>
</dependencies>
</ivy-module>
If you only want to download and install one set of jars, into a specified directory you can use the confs parameter:
java -jar ivy.jar -retrieve "plugin1/[artifact].[ext]" -confs plugin1
Finally, if you still want to use a programming API, you could invoke the run method called by the main class
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/Main.java?view=markup
Update 1
Groovy has built in support for invoking ivy tasks
import groovy.xml.NamespaceBuilder
def ant = new AntBuilder()
def ivy = NamespaceBuilder.newInstance(ant, 'antlib:org.apache.ivy.ant')
ivy.settings(file:"ivysettings.xml")
ivy.retrieve(pattern:"lib/[conf]/[artifact].[ext]")
ivy.report(toDir:'reports', graph:false)
Update 2
To set the location of your local Maven repository you need to use an ivysettings.xml file.
<ivysettings>
<settings defaultResolver='nexus' />
<resolvers>
<ibiblio name='nexus' root='http://myhost.mydomanin.com:8081/nexus' m2compatible='true' />
</resolvers>
</ivysettings>
Update 3
Just found an article that details how to invoke Ivy from Java
Let's say I have an ivy.xml that contains the following:
<dependency org="checkstyle" name="checkstyle" rev="4.3" />
And then I want to upgrade to Checkstyle 4.4, so I change my ivy.xml to contain:
<dependency org="checkstyle" name="checkstyle" rev="4.4" />
After a retrieve with the first configuration, I have the file checkstyle-4.3.jar. After the second configuration, I also have the file checkstyle-4.4.jar, and the file checkstyle-4.3.jar still exists.
Is there a way to have Ivy realize that the old file is an orphan, and remove it from the lib directory? The idea is that I don't want my developers' disk space usage to drastically increase every time I upgrade a tool.
Ideally I'd also want it removed from the local repository as well. I do realize that the intent of the local repository is that it is shared among projects, so it would not make sense to remove anything, as it would not know if the artifact was still in use in other projects. But there must be some kind of prune procedure...
I've been using Ivy 2.0.0, so I don't know if this applies to the version you're using.
The Ivy retrieve task has a sync attribute. Set this to true and unused/unknown files in your retrieved directory (lib in your case) will be removed. Keep in mind this will mean any manually copied artifacts in this directory which Ivy doesn't specifically resolve will be removed.
Also, note that if you use the sync option but Ivy resolves no dependencies (empty or missing ivy.xml, for example), the retrieve directory will be deleted.