Maven install assembly exclusion - maven

In my Maven project, I am using the maven-assembly-plugin bound to the package phase to create a distribution archive (zip) of the project. When I call mvn clean install to build & install the project, this archive gets installed into my local repository (.m2) as well. How can I exclude it from the installation? Or more generally, how can I exclude certain files/maven products from installation? I tried to relocate the assembly output out of the target directory but that wasn't the solution.

You can set the attach property of the maven-assembly-plugin to false, see the docs.
That way the file is generated but not attached to the project, excluding it from operations like install and deploy.
That being said, I don't recommend this as it can lead to unexpected behavior down the line.

Related

Maven plugin causes certain target folders not to be removed during clean

I am using the latest version of the cxf-xjc-plugin (https://cxf.apache.org/cxf-xjc-plugin.html) plugin, 3.1.0. This plugin generates Java classes for the given xsd files successfully. When I run a clean on the project, the target/generated-sources/java folder is left in place. I've simplified my POM to only use this plugin and the problem persists.
Older versions of the plugin do not do this as don't other similar plugins like jaxb2-maven-plugin.
I have looked at the projects POM and I don't see the clean plugin being configured to protect these files. What else could be going on to cause this?
What OS are you using? Could it be a permission issue where you built as root outside the ide once? I also saw this
Why doesn't Maven's mvn clean ever work the first time?

How to add ChargifyNET as a dependency to a TeamCity project?

We have recently switched to TeamCity 7.1.4 for our automated build system and attempting to add ChargifyNET dependency to an existing project. I have read up on the Build Artifact concept and the Dependent Build concept and they both seem pretty straight forward. However, the documentation really isn't clear on how to add a dependency that you do not need to build/compile.
Ideally, I would like to store the archive containing the ChargifyNET binaries in a folder and be able to reference that archive as an artifact when configuring dependencies for my project. How can I set this up?
So far, I've configured a separate project for ChargifyNET and declared the individual binaries from the archive as artifacts for this project (for example, %teamcity.agent.work.dir%/Chargify.NET/1.0.7/ChargifyNET.dll). Then I added a dependency to the main project for the ChargifyNET project artifacts.
When I build the main project I get a "Artifacts resolving failed" error. In the build log, under "Resolving artifact dependencies" I see no mention of the ChargifyNET artifacts.
How can I add ChargifyNET as a dependency to a TeamCity project? Do I need to get into a custom Ant script or can this be done from the UI?
Maybe the issue is with the artifact paths. Should 3rd party libraries be stored under the agent work directory or some other folder?
Is it best practice to have all 3rd party libraries checked in to a VCS repository? Perhaps a different solution would be to add an additional VCS root to the main project that points to the VCS repository holding 3rd party libraries.
Creating the Chargify.NET project as mentioned in the question was on track.
Create a build configuration under this project and enter a static build number (i.e. 1.0.7).
You have to "Run" the Chargify.NET build so TeamCity will create a dynamic build folder for it in the agent work directory.
Copy the Chargify.NET binaries into the folder created in step#2.
Modify the artifact path(s) from "%teamcity.agent.work.dir%/Chargify.NET/1.0.7/ChargifyNET.dll" to just "ChargifyNET.dll". This new path should refer directly to the files mentioned in step#3.
Modify the artifact path(s) in the Build Dependencies section of the main project to for Chargify.NET. They should look the same as in step#4 except that you may want to add a destination path (like so "ChargifyNET.dll=>trunk/bin").
Build the main project and you should see the files importing correctly.

Update site built by Tycho still contains erroneous dependency after re-build

I have built an Eclipse update site with Tycho, but when trying to install a feature from it into target IDE fails.
The update site builds fine; I can see it from a target Eclipse installation and select the feature for installation. However, the dependency check fails at start of install as it can't find a declared dependency (org.eclipselabs.xtext.utils.unittesting). This shouldn't be a dependency: it was erroneously included in MANIFEST.MF for one of my eclipse plugin projects.
I removed the dependency from the manifest and run mvn clean install again. The build reported success, but when I try to use the newly built update site it still complains that the dependency to org.eclipselabs.xtext.utils.unittesting (a) exists and (b) can't be satisfied.
So the question is: What else do I need to do to remove the dependency from the generated update site?
Thanks for any pointers.
PS: I know I could add the site for o.e.x.u.unittesting in the target eclipse installation so it can satisfy the dependency. However I don't want to do that; it's not needed for the feature to work and I don't want other users to have to add an unnecessary dependency.
Here is a list of cache locations that may have been involved in your scenario, and how to clear them
Target folder: If the target folder contain results from a previous build, this data may be used by a Maven build to speed up the build. Tycho doesn't make use of this feature, and AFAIK it shouldn't pick up anything existing from the target folder.
To be sure, always include the clean goal in your mvn calls.
Local Maven repository: In order to support builds of parts of a reactor, Tycho adds artifacts that have been built locally with mvn clean install to the target platform. If you are not aware of this feature, this can have various strange effects.
To avoid this, don't build with install unless you have to. Use mvn clean verify instead. Also: Deleting the file ~/.m2/repository/.meta/p2-local-metadata.properties resets what Tycho considers to be "locally installed".
Since Tycho 0.16.0, you can also disable this behaviour for one build through the command line switch -Dtycho.localArtifacts=ignore or for all builds by setting the same property in the settings.xml.
p2: The p2 update manager in Eclipse caches p2 repositories it has used since the start of Eclipse.
To force p2 to reload a repository, go to Preferences > Install/Update > Available Software Sites, select a repository and hit Reload. The repositories will also be reloaded if you re-start Eclipse.
Maybe I'm late to the game, but I still want to share my experience.
I'm using p2-maven-plugin to convert normal jar file to osgi bundle. It caches the converted jars in
~/.m2/repository/p2/osgi/bundle
Unless I change the version of my jar, p2 plugin always load the old bundle from that location.
Delete the old bundle in that folder and rebuilt projects again solve my problem.

Maven repository archive including build/plugin dependencies

My Client wants to be able to build our project from source but does not want to connect to the internet to get any dependencies for the build. Note this will include plugin dependencies.
My proposal is that we provide the client with an archive containing all the dependencies in the correct Maven repo file structure, including checksums and meta information. They can then use this as an internal maven repo.
I have configured the maven-assembly-plugin to create such an archive, however it doesn't include all the build/plugin dependencies that their Maven will require to perform the build.
Does anyone know of a way to include build time dependencies in the archive, or can suggest another way to grab these dependencies and wrap them up in the correct structure.
Many thanks,
Pat
On a clean repository, you can run mvn dependency:go-offline. This will download all the plugins and dependencies relevant to the project. You can verify that this is good by doing an offline build (mvn -o clean install).
Once this works fine, you can create an archive of the repository and the sources and pass it on.
Have you taken a look into the maven-dependency-plugin and furthermore i would suggest to do a complete compile and package and after that you can package the local repository from that user ($HOME/.m2/repository). Than you have everything which is needed to do a full compile etc.
Try mvn dependency:copy-dependencies. This will copy all the dependencies to a directory target\dependency.
However, I'm not certain whether this includes the dependencies necessary to build, as well and those necessary to install the compiled output.

Maven without (remote) repository?

I have a Maven 2 multi-module project and want to be sure everything is taken from my local checked-out source.
Is it possible to tell Maven to never download anything for the modules it has the source of? Do I have to disable the remote repositories?
Does Maven always have to go the expensive way of installing a module into the local repository, and then extracting it again for each of its dependents?
Does Maven automatically first recompile dependencies for a module if their local source changed, and then compile the dependent?
Is it possible to tell Maven to never download anything for the modules it has the source of?
No. Maven 2 only "sees" the current module while it builds. On the plus side, you can build part of the tree by running Maven in a module.
Do I have to disable the remote repositories?
Yes, use the "offline" option -o or -offline. Or use settings.xml with a proxy that doesn't have any files. This isn't what you want, though.
Does Maven always have to go the expensive way of installing a module into the local repository, and then extracting it again for each of its dependents?
Yes but it's not expensive. During the build, the file is copied (that was expensive ten years ago). When a dependency is used, Maven just adds the path to the file to the Java process. So the file isn't copied or modified again. Maven assumes that files in the local repository don't change (or only change once when a download/install happens).
Does Maven automatically first recompile dependencies for a module if their local source changed?
No. There were plans for Maven 3 but I can't find an option to enable something like that.
To solve your issues, you should install a local proxy (like Nexus).
Maven download stuffs (dependencies) only if it's not available in your local reposiotory ($USER_HOME/.m2/repository). If you do not want anything to be downloaded use offline mode. This can be done by using -o switch. E.g.
mvn -o clean install
There is nothing expensive in it. If you are building the complete parent project, it will build all the modules and then copy the artifacts to your local repository. Then, when you build a project that has dependencies on those project, Maven will just copy them from local repository on your hard disk to the package that is going to be created for current project.
No. I have been burnt. Maven does not compile dependencies automatically. There is a plugin called Maven Reactor Plug-in. This plugin enables you to build a project's dependencies before the project is built.

Resources