Generating UUID through Maven - java

I need to set a property in maven pom.xml file which should be a UUID. Can anybody tell me
what is the best possible way to set a property to UUID?
I am using a profile which launch the gigaspaces and gigaspaces requires group name which I
want to be unique(uuid). So, in my profile I want to set a groupName property value which
should change for each build. I wrote a UUIDGenerator plugin myself as I didn't found any.
So, I am looking How can this be achieved? Is writing a plugin better option or there is an
easier option.
Thanks,
Shekhar

Arian's solution (implementing a maven plugin) is IMO a clean way to implement your requirement (and +1 for his answer).
But if you don't plan to reuse your plugin somewhere else, a quick alternative would be to hack the pom using the GMavenPlus plugin. Here is an example showing how to do so using a Java class from a library to generate some uuid and set it as a property:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>Q3984794</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.safehaus.jug</groupId>
<artifactId>jug</artifactId>
<version>2.0.0</version>
<!-- the classifer is important!! -->
<classifier>lgpl</classifier>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>set-custom-property</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<classpath>
<element>
<groupId>org.safehaus.jug</groupId>
<artifactId>jug</artifactId>
<classifier>lgpl</classifier>
</element>
</classpath>
<source>
import org.safehaus.uuid.UUIDGenerator
def uuid = UUIDGenerator.getInstance().generateRandomBasedUUID()
project.properties.setProperty('groupName', uuid.toString())
</source>
</configuration>
</execution>
<execution>
<id>show-custom-property</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def props = project.properties
props.each {key, value -> println key + "=" + value}
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Just bind the plugin to a phase prior to the gigaspaces stuff.
The second execution is just there for demonstration purpose (to show the properties):
$ mvn generate-resources
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3984794 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- gmaven-plugin:1.3:execute (set-custom-property) # Q3984794 ---
[INFO]
[INFO] --- gmaven-plugin:1.3:execute (show-custom-property) # Q3984794 ---
downloadSources=true
downloadJavadocs=true
project.reporting.outputEncoding=UTF-8
project.build.sourceEncoding=UTF-8
groupName=814ff1a5-a102-426e-875c-3c40bd85b737
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...

First of all, if your set up requires something called "group name", you probably should provide a meaningful value. If it has to be unique, you can append some generated characters, like "MyApplication-10937410". Also, using a UUID seems to me like using a sledge-hammer to crack a nut. But this is independent of your actual problem, so here is the solution I propose:
If you have not already done so, create a maven plugin (there's an archetype for that). Add this dependency:
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
This is how your MOJO should look like:
/**
* Goal which generates a group name.
*
* #goal generate
* #phase initialize
*/
public class GroupNameGeneratorMojo extends AbstractMojo {
/**
* #parameter expression="${project}"
* #required
* #readonly
*/
private MavenProject project;
#Override
public void execute() throws MojoExecutionException {
String groupName = ... ;
project.getProperties().setProperty("uniqueGroupName", groupName);
}
}
In your actual projects pom, use ${uniqueGroupName} whereever you need it and configure your plugin like this
<build>
<plugins>
<plugin>
<groupId>the.plugin.groupid</groupId>
<artifactId>groupNameGenerator</artifactId>
<executions>
<execution>
<goals><goal>generate</goal></goals>
</execution>
</executions>
<plugin>

There is https://github.com/stevespringett/maven-uuid-generator which exposes a uuid for the build as ${project.build.uuid}. You can use it like
<plugins>
<plugin>
<groupId>us.springett</groupId>
<artifactId>maven-uuid-generator</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

Related

properties-maven-plugin does not set System propertey correctly

I am trying to set a system property in my java project with the maven plugin properties-maven-plugin. Here is my maven code:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<goals>
<goal>set-system-properties</goal>
</goals>
</execution>
<configuration>
<properties>
<property>
<name>system.property.name</name>
<value>${myvalue}</value>
</property>
</properties>
</configuration>
</executions>
</plugin>
...
I can see that is executed in the maven run:
[INFO] --- properties-maven-plugin:1.0.0:set-system-properties (default) # myproject ---
[INFO] Set 1 system property
[INFO]
But in then it is not present at runtime. For example I can not get it with System.getProperty("system.property.name")
I do not understand why. Funny thing is: It worked at one time and then it didn't, without me changing anything.
I also get this strange Eclipse error at the execution-tag: "Plugin execution not covered by lifecycle configuration: ..." but I think this is an Eclipse problem?
The system property is set for the build. After the build is over, it is gone. If you start the built program later, it does not have that system property.

How to built Eclipse plugin with Maven, Tycho and Jython?

I want to create an Eclipse plugin that is able to execute Python code. For this I want to use Jython. Additionally I use Maven for dependencies and want to use Maven for packaging.
My problem: (Solution added below)
I'm not able to build with Maven a eclipse plugin which is using Jython. Maven tells "BUILD SUCCESS" but Tycho & jython-compile-maven-plugin doesn't work together. The jython plugin is working because there are two jar as output, the normal jar and the jar with Jython extracted. The Tycho plugin is working because the normal jar is a valid plugin. But the jar with Jython extracted, which is needed, isn't a valid plugin. So how to bundle this 2 plugins correct?
Questions:
How to bring Tycho + jython-compile-maven-plugin together?
Iam using unpack-dependencies to unpack the python libs, but its working only once, if the folder is deleted/renamed/... Maven Update Project never called this again.
Because Maven, Tycho, Jython, M2E is new for me I ...:
created java project using Jython, packed as runnable jar with Maven, working
created eclipse plug-in, build with Maven & tycho plugins, working
created eclipse-plugin using Jython with "BundleShape: dir" without Maven, working
How to reproduce the problem?
Eclipse Photon, Modeling + installed M2E:
- Create new Plug-in Project name: ExampleMavenJythonEclipsePlugin, Version: 1.0.0.qualifier
- [x] This plug-in will make contributions to the UI (and no RC Application)
- [x] Create a plug-in using one of the templates
- View contribution using 3.x API
- View Class Name: SampleView
- Convert Project to Maven Project
- Replace POM with given given source
- Run Maven "Update Project...", refresh workspace after
- if there are pom errors like "Execution default-compile of goal org.eclipse.tycho:tycho-compiler-plugin [...]" do a change anywhere in pom and save (like insert newline, whitespace, tab, ...)
- Replace SampleView Class with given source (don't delete your package)
- Open plugin.xml, runtime, add classpath libs/jython-standalone.jar
- right click pom, run as, maven build..., goals: clean package
Testing:
- Put the plugin to eclipse plugin dir, restart eclipse
- window -> show view -> other
- Sample Category, Sample View
Additionally:
"run as Eclipse Application" doesn't mean that its working if packed.
Iam using Jython-Standalone.
Edit 1:
I made some progress. I did not understand correctly how Tycho works at the beginning. Tycho is using the Manifest / build.properties not the pom dependencies. The POM manages not the runtime dependencies, that why I needed to add the jython-standalone.jar to runtime. The jython-compile-maven-plugin isn't needed. I seems most important for Jython that the /Lib folder with python code is at the root point if in a jar. There are many possibilities to solve this, I am using a source folder created with eclipse named "pythonExtracted". The new source folder should now be in build.properties. Every source folder is copied to the root of the jar. The jython-standalone.jar ist in libs/ and is added to classpath manually. If you set "python.home" to the plugin.jar it looks working. But I can't resolve the bundle and the path "." points to the eclipse.exe not the jar like it is if a runnable jar is used.
I don't like that I now have 2 times the Lib folder with the same code. I tried to extract jython into lib/jython and set the runtime classpath. Tried to vary python home path. Nothing worked if the plugin is packed as jar. It really seems like it can only be /Lib inside of the jar. I tried to use Jython (not standalone) in libs but extracted Lib folder from standalone, but PySystemState / PythonInterpreter couldn't be resolved after packaged.
Solution:
- you need to add libs/jython to runtime classpath manually
- you need to create a source folder named: pythonExtracted (or adjust pom.xml below)
+ working if eclipse plugin packed as jar
+ Maven Update Project prepares the project
- python libs are twice in (extra ~10MB)
Solution: Pom.xml (without M2E config)
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ExampleMavenJythonEclipsePlugin</groupId>
<artifactId>ExampleMavenJythonEclipsePlugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<eclipse-release-url>http://download.eclipse.org/releases/photon</eclipse-release-url>
<maven-tycho-version>1.2.0</maven-tycho-version>
<maven-dependency-plugin-version>3.1.1</maven-dependency-plugin-version>
<maven-compiler-plugin-version>3.8.0</maven-compiler-plugin-version>
</properties>
<repositories>
<repository>
<id>eclipse-release</id>
<layout>p2</layout>
<url>${eclipse-release-url}</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin-version}</version>
<executions>
<execution> <!-- JythonStandalone to /libs, strip version -->
<id>copyLibs</id>
<phase>process-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<stripVersion>true</stripVersion>
<stripClassifier>true</stripClassifier>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<outputDirectory>${project.basedir}/libs</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpackPythonLibsFromJython</id>
<phase>initialize</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.python</includeGroupIds>
<includeArtifactIds>jython-standalone</includeArtifactIds>
<includes>Lib/**/*</includes>
<outputDirectory>${project.basedir}/pythonExtracted</outputDirectory> <!-- has to be a source folder -->
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${maven-tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${maven-tycho-version}</version>
<configuration>
<pomDependencies>consider</pomDependencies>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Solution: Pom.xml (with M2E config)
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ExampleMavenJythonEclipsePlugin</groupId>
<artifactId>ExampleMavenJythonEclipsePlugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<eclipse-release-url>http://download.eclipse.org/releases/photon</eclipse-release-url>
<maven-tycho-version>1.2.0</maven-tycho-version>
<maven-dependency-plugin-version>3.1.1</maven-dependency-plugin-version>
<maven-compiler-plugin-version>3.8.0</maven-compiler-plugin-version>
</properties>
<repositories>
<repository>
<id>eclipse-release</id>
<layout>p2</layout>
<url>${eclipse-release-url}</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin-version}</version>
<executions>
<execution> <!-- JythonStandalone to /libs, strip version -->
<id>copyLibs</id>
<phase>process-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<stripVersion>true</stripVersion>
<stripClassifier>true</stripClassifier>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<outputDirectory>${project.basedir}/libs</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpackPythonLibsFromJython</id>
<phase>initialize</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.python</includeGroupIds>
<includeArtifactIds>jython-standalone</includeArtifactIds>
<includes>Lib/**/*</includes>
<outputDirectory>${project.basedir}/pythonExtracted</outputDirectory> <!-- has to be a source folder -->
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${maven-tycho-version}</version>
<extensions>true</extensions>
</plugin>
<!-- Enable the replacement of the SNAPSHOT version in the final product
configuration
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<version>${maven-tycho-version}</version>
<executions>
<execution>
<phase>package</phase>
<id>package-feature</id>
<configuration>
<finalName>${project.artifactId}_${unqualifiedVersion}.${buildQualifier}</finalName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${maven-tycho-version}</version>
<configuration>
<includeAllDependencies>true</includeAllDependencies>
</configuration>
</plugin>-->
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${maven-tycho-version}</version>
<configuration>
<pomDependencies>consider</pomDependencies>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>validate-version</goal>
<goal>validate-id</goal>
<goal>build-qualifier</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[${maven-dependency-plugin-version},)
</versionRange>
<goals>
<goal>copy</goal>
<goal>unpack-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Solution: Activator.java (set it in plugin.xml)
package examplemavenjythoneclipseplugin.views;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
public static Bundle bundle = null;
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* #see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
if (bundle == null) {
bundle = context.getBundle();
}
}
/*
* (non-Javadoc)
* #see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
}
/**
* Returns the shared instance
*
* #return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
Solution: SampleView.java
package examplemavenjythoneclipseplugin.views;
import java.io.File;
import java.util.Properties;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
import org.osgi.framework.Bundle;
import org.python.core.PySystemState;
import org.python.util.PythonInterpreter;
public class SampleView extends ViewPart {
private static void pythonTest(final String home) {
final Properties propsPre = System.getProperties();
final Properties propsPost = new Properties();
// suppress warning console encoding not set
propsPost.put("python.console.encoding", "UTF-8");
// if no Lib folder is found, constructor of PythonInterpreter fails, but this isn't useful
propsPost.put("python.import.site", "false");
// set python home path / cache dir for Jython (just package information)
propsPost.put("python.cachedir", new File(home, "cachedir").getAbsolutePath());
propsPost.put("python.home", new File(home).getAbsolutePath());
// used for our own "System.out" => we can read it later with ease
final java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
// needed only once in any application before any other Python/Jython code is used.
PySystemState.initialize(propsPre, propsPost, new String[0]);
try (final PythonInterpreter interpreter = new PythonInterpreter();) {
interpreter.setOut(new java.io.PrintStream(out));
interpreter.exec("print('Hello World')"); // checks if start is fine
interpreter.exec("print ' '");
interpreter.exec("print('importing sys'); import sys; print('done');"); // should work even if Lib not found
interpreter.exec("print 'prefix:', sys.prefix");
interpreter.exec("print ' '");
interpreter.exec("print 'System path:', sys.path");
interpreter.exec("print('importing os'); import os; print('done');"); // needs access to lib folder
interpreter.exec("print('Hello World')"); // if anything above fails, null is printed not Hello World
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Output:",
out.toString() + "\n" + (home));
} catch (Throwable t) {
MessageDialog.openError(Display.getDefault().getActiveShell(), "Jython failed",
out.toString() + "\n" + t.toString());
t.printStackTrace();
}
}
#Override
public void createPartControl(Composite parent) {
/* 1) Show Python home path
* 2) make Python home path changable
* 3) create button to start PythonInit & test
*/
// I have no clue why, getBundle failed in various situations, the plugin Activator gets the bundle better.
// final Bundle bundle = Platform.getBundle("ExampleMavenJythonEclipsePlugin"); // Argument = Manifest.Bundle-SymbolicName
final Bundle bundle = Activator.bundle; // start(BundleContext context) => context.getBundle()
// 1 & 2) Create input showing the home path used (fallback "." = not valid in this working version but is vor runnable jar)
parent.setLayout(new FormLayout());
final Text input = new Text(parent, SWT.SINGLE);
FormData d = new FormData();
d.top = new FormAttachment(parent, 0);
d.left = new FormAttachment(parent, 0);
d.right = new FormAttachment(100, 0);
input.setLayoutData(d);
try {
File b = FileLocator.getBundleFile(bundle);
input.setText(b.getAbsolutePath());
} catch (Throwable e) {
input.setText(".");
}
// 3) create button to start test
final Button button = new Button(parent, SWT.PUSH);
d = new FormData();
d.top = new FormAttachment(input, 5);
d.left = new FormAttachment(parent, 0);
d.right = new FormAttachment(100, 0);
button.setLayoutData(d);
button.setText("test");
button.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
pythonTest(input.getText());
}
});
}
#Override
public void setFocus() {
}
}
Solution: Maven Console "mvn clean package"
[INFO] Scanning for projects...
[INFO] Computing target platform for MavenProject: ExampleMavenJythonEclipsePlugin:ExampleMavenJythonEclipsePlugin:1.0.0-SNAPSHOT # D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\pom.xml
[INFO] Fetching p2.index from http://download.eclipse.org/releases/photon/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/photon/
[INFO] Adding repository http://download.eclipse.org/releases/photon
[INFO] Fetching p2.index from http://download.eclipse.org/technology/epp/packages/photon/
[INFO] Fetching p2.index from http://download.eclipse.org/technology/epp/packages/photon/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/photon/201806271001/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/photon/201806271001/
[INFO] Fetching content.xml.xz from http://download.eclipse.org/releases/photon/201806271001/
[INFO] Fetching content.xml.xz from http://download.eclipse.org/releases/photon/201806271001/
[INFO] Fetching content.xml.xz from http://download.eclipse.org/releases/photon/201806271001/ (248,94kB at 247,04kB/s)
[INFO] Fetching content.xml.xz from http://download.eclipse.org/releases/photon/201806271001/ (701,55kB at 349,82kB/s)
[INFO] Resolving dependencies of MavenProject: ExampleMavenJythonEclipsePlugin:ExampleMavenJythonEclipsePlugin:1.0.0-SNAPSHOT # D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\pom.xml
[INFO] Resolving class path of MavenProject: ExampleMavenJythonEclipsePlugin:ExampleMavenJythonEclipsePlugin:1.0.0-SNAPSHOT # D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\pom.xml
[INFO]
[INFO] -----
[INFO] Building ExampleMavenJythonEclipsePlugin 1.0.0-SNAPSHOT
[INFO] ---------------------------[ eclipse-plugin ]---------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # ExampleMavenJythonEclipsePlugin ---
[INFO] Deleting D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\target
[INFO]
[INFO] --- tycho-packaging-plugin:1.2.0:build-qualifier (default-build-qualifier) # ExampleMavenJythonEclipsePlugin ---
[INFO] The project's OSGi version is 1.0.0.201812181615
[INFO]
[INFO] --- tycho-packaging-plugin:1.2.0:validate-id (default-validate-id) # ExampleMavenJythonEclipsePlugin ---
[INFO]
[INFO] --- tycho-packaging-plugin:1.2.0:validate-version (default-validate-version) # ExampleMavenJythonEclipsePlugin ---
[INFO]
[INFO] --- maven-dependency-plugin:3.1.1:unpack-dependencies (unpackPythonLibsFromJython) # ExampleMavenJythonEclipsePlugin ---
[INFO] Unpacking D:\Programme\.m2\org\python\jython-standalone\2.7.1\jython-standalone-2.7.1.jar to D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\pythonExtracted with includes "Lib/**/*" and excludes ""
[INFO]
[INFO] --- maven-dependency-plugin:3.1.1:copy (copyLibs) # ExampleMavenJythonEclipsePlugin ---
[INFO] Configured Artifact: org.python:jython-standalone:?:jar
[INFO] Copying jython-standalone-2.7.1.jar to D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\libs\jython-standalone.jar
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # ExampleMavenJythonEclipsePlugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\src\main\resources
[INFO]
[INFO] --- tycho-compiler-plugin:1.2.0:compile (default-compile) # ExampleMavenJythonEclipsePlugin ---
[INFO] Compiling 2 source files to D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) # ExampleMavenJythonEclipsePlugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\src\test\resources
[INFO]
[INFO] --- target-platform-configuration:1.2.0:target-platform (default-target-platform) # ExampleMavenJythonEclipsePlugin ---
[INFO]
[INFO] --- tycho-packaging-plugin:1.2.0:package-plugin (default-package-plugin) # ExampleMavenJythonEclipsePlugin ---
[INFO] Building jar: D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\target\ExampleMavenJythonEclipsePlugin-1.0.0-SNAPSHOT.jar
[INFO]
[INFO] --- tycho-p2-plugin:1.2.0:p2-metadata-default (default-p2-metadata-default) # ExampleMavenJythonEclipsePlugin ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 55.097 s
[INFO] Finished at: 2018-12-18T17:16:51+01:00
[INFO] ------------------------------------------------------------------------

Query DSL & Maven: Classes not generated, but only on command line (in eclipse it is working fine)

We are using a setup with Spring Boot, Hibernate, Query DSL and Maven with Java 1.8
Recently, I've added Query DSL to the project with the configuration listed below. To make it work, I had to configure the Java Compiler in the eclipse project settings to allow Annotation Processing and also add the Query DSL .jar file to the eclipse Annotation Factory Path.
This setup worked as expected. It generated the custom Q classes and I could use them in my code. When now running the mvn clean install on the command line, every class in my code throws the error cannot find symbol, because the class is missing. Is there anything else I need to configure - similar to the .jar file in the eclipse settings - to make the build process work?
EDIT: This question is not a duplicate of this question because I did not ask why this error (cannot find a symbol) occurs but rather how to configure QueryDSL to also work on the command line.
EDIT2: I have now tried to integrate the build-helper-maven-plugin to use multiple source paths as an input. This did not help either. I also tried to generate the files into a src folder. It did not help either.
When I first compile the library in eclipse, the mvn compile goes through on the command line, but mvn clean compile still fails, because it just uses the compiled files of eclipse again. The apt-maven-plugin is executed, which can be seen just before the build process fails:
[INFO] --- apt-maven-plugin:1.1.3:process (default) # project1 ---
[INFO]
[INFO] --- build-helper-maven-plugin:1.9.1:add-source (add-source) # project1 ---
[INFO] Source directory: C:\Users\user1\git\project1\src\main\generated added.
[INFO]
[INFO] --- maven-processor-plugin:2.2.4:process (process) # project1 ---
[ERROR] diagnostic: [...]
EDIT3: When I remove every import statement which is referring to the Q classes, the build process goes through (obviously). It is, however, remarkable, that the Q classes get compiled correctly in that case. They appear in the target folder as .class files as they should. Could it be, that the Q classes are compiled too late?
Here is an excerpt of the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
[...]
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
<dependencies>
[...]
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.1.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>4.1.3</version>
</dependency>
</dependencies>
<build>
<defaultGoal>spring-boot:run</defaultGoal>
<plugins>
[...]
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
[...]
</build>
</project>
This is the configuration of the eclipse project settings:
This is the error message which is displayed in the console:
[INFO] --- maven-processor-plugin:2.2.4:process (process) # project1 ---
[ERROR] diagnostic: C:\Users\user1\git\project1\src\main\java\com\project1\repository\UserRepositoryImpl.java:3: error: cannot find symbol
import static com.project1.domain.QUser.user;
^
symbol: class QUser
location: package com.project1.domain
[ERROR] diagnostic: C:\Users\user1\git\project1\src\main\java\com\project1\repository\UserRepositoryImpl.java:3: error: static import only from classes and interfaces
import static com.project.domain.QUser.user;
^
This is old question but this is how i find my solution, added classifier for jpa dependency:
<!-- BEGIN: 'querydsl-jpa' -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl-jpa.version}</version>
<classifier>apt</classifier>
</dependency>
<!-- END: 'querydsl-jpa' -->
My complete pom:
<!-- BEGIN: BUILD -->
<build>
<!-- BEGIN: PLUGINS -->
<plugins>
<!-- BEGIN: apt-maven-plugin -->
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>${apt.version}</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/apt</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<!-- END: apt-maven-plugin -->
</plugins>
<!-- END: PLUGINS -->
</build>
<!-- END: BUILD -->
<!-- BEGIN: DEPENDENCIES -->
<dependencies>
<!-- *********************************************** -->
<!-- BEGIN: 'QUERYDSL DEPENDENCIES' -->
<!-- BEGIN: 'querydsl-apt' -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl-apt.version}</version>
</dependency>
<!-- END: 'querydsl-apt' -->
<!-- BEGIN: 'querydsl-jpa' -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl-jpa.version}</version>
<classifier>apt</classifier>
</dependency>
<!-- END: 'querydsl-jpa' -->
<!-- *********************************************** -->
<!-- END: 'QUERYDSL DEPENDENCIES' -->
</dependencies>
For me, it didn't work because it conflicted with maven-compiler-plugin with already set annotation processor. Just deleted the use of apt-maven-plugin and added its annotation processor in maven-compiler-plugin.
<build>
<plugins>
<!-- related to issues:-->
<!-- - https://github.com/querydsl/querydsl/issues/2654 -->
<!-- - https://github.com/querydsl/querydsl/issues/2242 -->
<!-- Using apt-maven-plugin conflicts with other annotation processors (like mapStruct) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>5.0.0</version>
<classifier>jpa</classifier>
</path>
<path>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>2.2.3</version>
</path>
<path>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</path>
<!-- other annotation processors -->
</annotationProcessorPaths>
</configuration>
</plugin>
<!-- <plugin>-->
<!-- <groupId>com.mysema.maven</groupId>-->
<!-- <artifactId>apt-maven-plugin</artifactId>-->
<!-- <version>1.1.3</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>process</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <outputDirectory>target/generated-sources</outputDirectory>-->
<!-- <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
</plugins>
</build>
But there is an issue with using querydsl annotation processor in maven-compiler-plugin. You have to add jakarta.persistence-api and javax.annotation-api.
I would rather use profile to generate these Qclasses only when db change occurs.
cons:
-your diff in pull requests is clean when you don't change db schema because for each generation these files tend to generate differently for some reason (atleast in my case).
-you can manage witch of tables present in your db will have Qclasses (sometimes it is a pain when you forget to regenerate them after changing db schema)
-well not that it is lots of time . but builds are faster if You don't change schema and profile is turned off.
Try something like this and turn on profile when You want to generate changed schema Qclasses :
<properties>
<whitelisted.tables>
user_accunt,
other
</whitelisted.tables>
</properties>
<profiles>
<profile>
<id>generate</id>
<build>
<plugins>
<plugin>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>${querydsl.version}</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbcDriver>org.postgresql.Driver</jdbcDriver>
<jdbcUrl>jdbc:postgresql://localhost:port/dbname</jdbcUrl>
<packageName>your.package.name.for.q</packageName>
<jdbcUser>dbusername</jdbcUser>
<jdbcPassword>dbpassword</jdbcPassword>
<targetFolder>${project.basedir}/src/main/java/</targetFolder>
<spatial>true</spatial>
<tableNamePattern>${whitelisted.tables}</tableNamePattern>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The generated-source directory are not automatically included in the jar.
You need to use the Maven build helper plugin to fix this issue, for example:
https://github.com/alexec/javahelp-skeleton/blob/master/pom.xml
You can try out few things:
1.try to put <clearOutputDir>false</clearOutputDir> in your configuration tag
2. Sometimes classes might not be getting generated before the compile phase. So try to put phase in your plugin
<execution>
<phase>generate-sources</phase>
<goals>
<goal>...</goal>
</goals>
</execution>
By convention Maven assumes all source code is in 'src/main/java', compiles this and put all *.class file in target.
So if you have a class 'Alien.java' in <project-root>/alice/in/wonderland, your won't be able to access it (in src/main/java) because maven puts everything from src/main/java in classpath for your compiler and hence compiler is unaware of any source code (*.java) anywhere else.
In your case you are generating your source code in directory target/generated-sources/java, so you will have to tell maven about it. As mentioned in some other answers you may use build-helper-plugin for this, let maven know that your source resides on target/generated-sources/java by
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/java</source>
<source>alice/in/wonderland</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Edit: You have mentioned wrong path in build-helper-plugin
I see although you are using build helper plugin but you are using wrong path
--- build-helper-maven-plugin:1.9.1:add-source (add-source) # project1 ---
[INFO] Source directory: C:\Users\user1\git\project1\src\main\generated added.
Instead of src\main\generated you should use <source>target/generated-sources/java</source>

Using AspectJ annotations in maven project: weaving is not working

I am trying to use AspectJ in a simple project without using Spring, and while I have seen similar questions and my code seems to be correct, I don't understand why it's not working. I'm using Eclipse Oxygen 4.7.3 (not using AJDT tools), JDK 7, maven 3.5.2, and my code is as follows:
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>aspect-tutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.plugin.version>3.5.1</maven.compiler.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.7</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<complianceLevel>1.7</complianceLevel>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
MainApp.java
package com.pkg;
public class MainApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
HelloWorld a = new HelloWorld();
a.printHello();
}
}
HelloWorld.java
package com.pkg;
public class HelloWorld {
private String name;
public void setName(String name) {
this.name = name;
}
public void printHello() {
System.out.println("Print Hello...");
}
}
TestAspect.java
package com.pkg;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
#Aspect
public class TestAspect {
#Before("execution(* com.pkg.HelloWorld.printHello(..))")
public void testBefore2(){
System.out.println("Yeeha");
}
}
Running mvn clean install is successful, but the output only prints the "Print Hello..." part. Should I use a different approach? (Maybe use a .aj file instead, or try load-time-weaving) Any help appreciated.
The problem is the configuration of both AspectJ Maven and Maven Compiler. My POMs for AspectJ usually look a bit different than yours (a few more settings), but here is yours with minimal changes in order to make it work:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>aspect-tutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.plugin.version>3.5.1</maven.compiler.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.13</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<configuration>
<complianceLevel>1.7</complianceLevel>
<source>1.7</source>
<target>1.7</target>
</configuration>
<executions>
<execution>
<!-- IMPORTANT -->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<!-- IMPORTANT -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<mainClass>com.pkg.MainApp</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
See how I set incremental compilation to false for Maven compiler? This is due to an old bug (still unfixed) which actually inverts the switch, so in order to make incremental compilation work you have to "deactivate" it. Very weird.
You also need to define executions for the process-sources phase for AspectJ Maven.
Besides, I upgraded to AspectJ Maven 1.11 and thus also to AspectJ runtime 1.8.13.
I also added Maven Exec plugin in order to easily prove that it is working now. Just call mvn clean compile exec:java and check the output:
(...)
[INFO] --- aspectj-maven-plugin:1.11:compile (default) # aspect-tutorial ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # aspect-tutorial ---
[INFO] Nothing to compile - all classes are up to date
(...)
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) # aspect-tutorial ---
Yeeha
Print Hello...
(...)
Otherwise I support what NĂ¡ndor said: Make sure you use AspectJ plugins for Eclipse or IDEA if you also want to run your aspect-enhanced Java code from an IDE.
How you you run your app? Purely from maven or from within Eclipse? Do you have Eclipse to automatically build your projects? If yes, you probably won't have too much success with compile time weaving, because Eclipse will overwrite your Maven built classes with Eclipse built classes. Without the AJDT feature installed, and properly set up workspace project with AspectJ nature, the resulting compiled code won't be "enhanced" by the AspectJ weaver.

Manually set Assembly package name, but Install plugin ignores them

I am having a problem with some functionality I need configured.
Here is a part of my POM, where I configured a project to be assembled into two different files: FirstNameProject-VERSION-bin.zip and SecondNameProject-VERSION-bin.zip.
The idea is that I had to maintain those names set, even if the original artefact is common.
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.project.my</groupId>
<artifactId>MyGenericProject</artifactId>
<name>Generic Project</name>
<version>2.0.2-SNAPSHOT</version>
...
<build>
<plugins>
....
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>first</id>
<configuration>
<finalName>FirstNameProject-${project.version}-bin</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/resources_first.xml</descriptor>
</descriptors>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
<execution>
<id>second</id>
<configuration>
<finalName>FirstNameProject-${project.version}-bin</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/resources_second.xml</descriptor>
</descriptors>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
This is working properly and in the mvn package logs I can see:
[INFO] --- maven-assembly-plugin:2.2.1:single (first) # MyGenericProject ---
[INFO] Reading assembly descriptor: src/main/assembly/resources_first.xml
[INFO] Building zip: C:\MyPath\MyProject_trunk\target\FirstNameProject-2 .0.2-bin.zip
[INFO]
[INFO] --- maven-assembly-plugin:2.2.1:single (second) # MyGenericProject ---
[INFO] Reading assembly descriptor: src/main/assembly/resources_second.xml
[INFO] Building zip: C:\MyPath\MyProject_trunk\target\SecondNameProject-2.0 .2-bin.zip
The problem is that, at during install, it just reverts to the generic name and install the the rightly named file as the Generic one!
[INFO] --- maven-install-plugin:2.3.1:install (default-install) # MyGenericProject ---
[INFO] Installing C:\MyPath\MyProject_trunk\target\MyGenericProject-2.0.2-SNAPSHOT.jar to C:.m2\repository\com\project\my\MyGenericProject\2.0.2-SNAPSHOT\MyGenericProject-2.0.2-SNAPSHOT.jar
[INFO] Installing C:\MyPath\MyProject_trunk\pom.xml to C:.m2\repository\com\project\my\MyGenericProject\2.0.2-SNAPSHOT\MyGenericProject-2.0.2-SNAPSHOT.pom
[INFO] Installing C:\MyPath\MyProject_trunk\target\FirstNameProject-2.0.2-SNAPSHOT-bin.zip to C:.m2\repository\com\project\my\MyGenericProject\2.0.2-SNAPSHOT\MyGenericProject-2.0.2-SNAPSHOT.zip
I am imagining that this is because the install plugin has no visibility on exactly how the assembly plugin was configured so I ask you: how can I configure the install plugin so that I will end up with FirstNameProject-VERSION-bin.zip and SecondNameProject-VERSION-bin.zip installed in my repository??
I hope I was clear enough,
Thanks
It sounds like Maven is "attaching" the assembly artifact to the project under the default name. The first option is to scour the assembly plugin configuration to see if there's a way to control this. Looking through it myself, I don't see a way to do this. I would have thought it would have used your final name configuration, but if it doesn't, it doesn't.
The workaround I can offer, and I would hope someone can offer something more standard, is to configure the assembly to NOT attach itself.
Next, take the file it creates, the one with the name you want, and use the build-helper plugin to attach the file under the precise coordinates that you want.

Categories