Release a SQL artifact in Maven - sql

How do I tell Maven to also publish the SQL artifact for the DBA?
Here's the thing: when we release every new version of our Maven application, we need to publish two artifacts:
The web application (e.g. app-1.2.0.war file) -- for the WebSphere guy.
The database changes for this version (e.g. dba-1.2.0.sql file) -- for the DBA.
The SQL changes file is currently src/main/database/dba.sql, but I can change that dir or file name if necessary.
As of now Maven publishes the war artifact automatically (mvn clean deploy) to the artifact repository, and that's perfect. However, I wanted it to publish the SQL file at the same time, in the same command as well... and it doesn't.
How can I do that?
I see that we can tell Maven to publish extra artifacts (e.g. sources, javadoc) at once, so I guess it should be possible to publish SQL files as well, but this is just a guess.

You can use the Build Helper plugin for that.
But the file name is computed from artifactid, version, type and classifier.
If you need to absolutely push a different name with a different artifactId, you will need either to mvn deploy:deploy-file ... (from a command in your CI or with an ant script in the pom) or create an additional pom file and launch maven against it.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>src/main/database/dba.sql</file>
<type>sql</type>
<!-- <classifier>xxx</classifier> -->
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
link to the source: https://www.mojohaus.org/build-helper-maven-plugin/usage.html

Related

Update Update-Site From Maven Repository

I have a normal Eclipse plug-in build with Tycho, and want to build an update site with the very same Tycho. My problem is figuring out how to get the artifact from its Maven GAVs (or optionally the JAR) into the update site.
What I tried:
<plugin>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-p2-extras-plugin</artifactId>
<version>${tycho.version}</version>
<executions>
<execution>
<id>add-to-update-site</id>
<phase>install</phase>
<goals>
<goal>mirror</goal>
</goals>
<configuration>
<source>
<repository>
<url>${project.baseUri}/target/repository</url>
</repository>
</source>
<destination>${project.basedir}</destination>
<append>true</append>
</configuration>
</execution>
</executions>
</plugin>
This takes the repository from target/repository and merges it with the one in the base directory of the project. So every plug-in in target/repository will be added to the update site.
This works with a target platform file, but of course not with Maven GAVs or JAR. I tried adding the plug-in as a dependency and using dependency:copy-dependencies, but this will not create a P2 repository.
There is the plug-in tycho-p2-repository:assemble-repository, but I'm not sure it can help me create a P2 repository for tycho-p2-extras-plugin to consume. Or even as standalone.
I found reficio's p2-maven-plugin, which can generate P2 repositories from JARs, but it doesn't support Tycho at all.
I feel like I'm only one step away from a solution. So how do I build a P2 repository from Maven GAVs (or JAR files)?
That is not possible with Tycho. So I used the command line:
SET ECLIPSE_HOME=S:/Development/Eclipse 2018-12
SET EQUINOX_VERSION=1.5.200.v20180922-1751
SET CURRENT_PATH=%~dp0
SET SOURCE_REPOSITORY=%CURRENT_PATH%\dropin
SET TARGET_REPOSITORY=%CURRENT_PATH%\
java -jar "%ECLIPSE_HOME%/plugins/org.eclipse.equinox.launcher_%EQUINOX_VERSION%.jar"
-application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher
-metadataRepository "file:/%TARGET_REPOSITORY%" -artifactRepository "file:/%TARGET_REPOSITORY%"
-source "%SOURCE_REPOSITORY%" -publishArtifacts -append
However I haven't been able to create categories, so the repository appears to be empty on default.

Including maven built assemblies in another module

I have 2 maven modules. One module builds bunch of zip files using maven-assembly-plugin. Second module needs to include some of the zip files built by the first module in its package. What is the way to do this. Thank you.
The easiest thing would be to deploy the zips to a repository. For the local repository use install:install-file and for central repositories use deploy:deploy-file.
You can declare the zips as dependencies in your second module.
So someone else mentioned to deploy it to your repository. If you're already setup to deploy built artifacts to a repository this is easy, if not, check out http://maven.apache.org/plugins/maven-deploy-plugin/
Next, you need to use a plugin to get the zip file checked out of the repository. You could use shade, or the maven-dependency-plugin. Let's assume maven-dependency-plugin http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
So add this to your maven pom file in the plugins section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.artifact.group.id</groupId>
<artifactId>my-artifact</artifactId>
<version>My-version</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/see</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Obviously you need to change the specifics of the artifact. That will unzip your zip file into target/see. If you want the actual zip file (which seems like what you were asking for but it's not clear), just change the goal from "unpack" to "copy-dependencies". You might also have to remove the outputDirectory or change some other bit of the configuration. Just play with it to get it where you need it, and see the page on the maven-dependency-plugin I mentioned above for more details.
Hope that helps.

Inter-module dependencies on additional assemblies during a Maven release

We have a multi module project with following modules:
Database
Persistence
Business
Application
The 'Database' project is a jar project that creates an additional assembly using the 'maven-assembly-plugin'. This additional assembly contains the database schema.
The plugin configuration is as follows:
<plugin>
<!-- create a zip file that contains all the db migration scripts. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-schema</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>db-schema-descriptor.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
The 'Application' project creates a zipped version of the the application directory structure. Therefore it references the schema assembly in order to extract and copy it to the appropriate location in the application directory structure. The reference is expressed as ordinary maven dependency:
<dependency>
<groupId>my.application</groupId>
<artifactId>persistence</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>db-schema</classifier>
</dependency>
At least there is a multi module project that aggregates the 4 sub modules in order to build the application in one step.
Running 'mvn deploy' on the aggregate project works fine. The database schema assembly is extracted and copied. But when running a 'mvn release:prepare' on the aggregate project building the 'Application' project fails with the error notification that maven is unable to find the schema assembly with version '0.0.1'. The log file states that the 'Persistence' project has been built before the 'Application' project and that the 'database schema' assembly has been built.
Anyone an idea what I am doing wrong?
See http://www.mail-archive.com/users#maven.apache.org/msg117321.html for an answer
Using the command line 'mvn -DpreparationGoals=install release:prepare' solves the problem. With that command line the prepare release:prepare goals runs the install goal first which installs the release assemblies in the local repository. Later these assemblies can be referenced during the release process.

Execution point between prepare-package and package in Maven build-process

The package phase of a project with packaging war, prepares an exploded-war in the target folder and packages this into the final war-file.
Is it possible to make some changes, editing files, removing files and so on, between prepare-package and package phases? I'm searching for an extension point (Maven execution-phase) where the resources are already copied and in the exploded-war structure.
[maven phase] Copy resources and explode to target/{finalName}.
[custom] Do some complex custom changes (e.g. implemented with maven-antrun).
[maven phase] Package the changed stuff into the final war.
I thought this could be possible between the phases prepare-package and package. Unfortunately after the prepare-package no exploded war is available to be changed and packaged later.
Can you give me a hint how to achieve this? Thank you very much.
This configuration calls the exploded goal in the prepare-package phase. This gives you the chance to work on the exploded war directory in subsequent plugin definitions e.g. maven-antrun.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
It sound to me like you should bind the antrun task to the prepare package phase, because at this point the resources have already been processed see Lifecycle Reference.

How to remove generated build artifacts from Maven's target directory?

How to remove generated build artifacts from Maven's target directory? Maven generates a jar or war file to target directory. I'd like to remove that file after maven has installed the jar/war file to local repository (that is, after maven has executed the 'install' goal). The remove could happen either at install goal or separate goal I execute manually.
Note, that I'd like leave other parts of target directory intact, for example target/site and target/surefire-reports.
Just use the clean plugin and run an execution after the install phase:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>${project.build.outputDirectory}</directory>
<includes>
<include>**/*.jar</include>
</includes>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
There is nothing built into Maven that can do this. You could use the antrun plugin to execute an Ant script after install that deletes the artifact, or use the exec plugin to use the command line to delete the artifact, or write your own plug-in.
I suggest there is little value, if any, in doing any of these things. Maven is designed to place intermediate and final artifacts in target to make follow-on builds more efficient. The reason that there is nothing available to do this already is an indicator that this is of little value. If it is of value to you, you have a few options.
I know I am a little bit late. But I guess the issue was, that a maven project archives the artifacts automatically. In my case, I disabled the automatic archiving and just archived the artifacts manually using the post build actions. This way, only the artifacts that I am interested in are archived. I am willing to leave the generated artifacts on disk until the next build runs.