Maven parent pom variables are not resolved - java

I have the following POM structure:
./foobar-common/pom.xml
./abc-window/pom.xml
./abc-datasource/pom.xml
Both abc-window pom.xml is as follows:
<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>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-window</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>abc-window</name>
<parent>
<relativePath>../foobar-common/pom.xml</relativePath>
<groupId>hu.abc.ringcore</groupId>
<artifactId>foobar-common</artifactId>
<version>1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-datasource</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>
abc-datasource pom.xml is as follows:
<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>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-datasource</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>abc-datasource</name>
<parent>
<relativePath>../foobar-common/pom.xml</relativePath>
<groupId>hu.abc.ringcore</groupId>
<artifactId>foobar-common</artifactId>
<version>1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-event</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-variable</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-variableintf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>hu.foobar.ring</groupId>
<artifactId>RateSorszamIntf</artifactId>
<version>${ringcore-services.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
The foobar-common pom.xml is as follows:
<project>
<modelVersion>4.0.0</modelVersion>
<name>Maven Default Project</name>
<groupId>hu.foobar.ringcore</groupId>
<artifactId>foobar-common</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.10</junit.version>
<spring.version>3.1.2.RELEASE</spring.version>
<spring-security.version>2.0.6.RELEASE</spring-security.version>
<commons-logging.version>1.1.1</commons-logging.version>
<dom4j.version>1.6.1</dom4j.version>
<javaee-api.version>6.0</javaee-api.version>
<mycila-event.version>3.0</mycila-event.version>
<ringcore-services.version>1.3.4-SNAPSHOT</ringcore-services.version>
<commons-lang3.version>3.1</commons-lang3.version>
</properties>
</project>
My problem is that if I do an mvn install in abc-datasource the dependency versions are pulled from the parent pom properties as expected. However if I do mvn install from abc-window that references abc-datasource then the versions are not resolved, I get:
[ERROR] Failed to execute goal on project abc-window: Could not resolve dependencies for project hu.abc.ringcore:abc-window:jar:1.0-SNAPSHOT: Failed to collect dependencies for [junit:junit:jar:4.10 (test), hu.abc.ringcore:abc-datasource:jar:1.0-SNAPSHOT (compile)]: Failed to read artifact descriptor for org.apache.commons:commons-lang3:jar:${commons-lang3.version}: Could not transfer artifact org.apache.commons:commons-lang3:pom:${commons-lang3.version} from/to central (http://repo.maven.apache.org/maven2): IllegalArgumentException: Illegal character in path at index 70: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/${commons-lang3.version}/commons-lang3-${commons-lang3.version}.pom
Both project have the same parent pom, so why doesn't it work..?

Use dependencyManagment in parent pom
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
add all versions in parent pom, and use dependencies without version in children
EDIT
/pom.xml <-parent pom
/abc-window/pom.xml <-child module
/abc-datasource/pom.xml <-child module
and parent pom should contains
<project
...
<properties>
...
</properties>
<modules>
<module>abc-datasource</module>
<module>abc-window</module>
</modules>
<build>
<pluginManagment>
...
</pluginManagment>
</build>
<dependencyManagment>
...
</dependencyManagment>
</project>

The parent in abc-window is listed as:
<parent>
<relativePath>../foobar-common/pom.xml</relativePath>
<groupId>hu.abc.ringcore</groupId>
<artifactId>foobar-common</artifactId>
<version>1.0</version>
</parent>
The parent in abc-datasource is listed as:
<parent>
<relativePath>../foobar-common/pom.xml</relativePath>
<groupId>hu.ratesoft.ringcore</groupId>
<artifactId>foobar-common</artifactId>
<version>1.0</version>
</parent>
So, they do not have the same groupId.

Related

alter pom file for heroku deployment

I'm trying to deploy an Eclipse jee dynamic web app to heroku. I need to modify the pom file but I'm not sure how.
Here's what I need to add but I'm not sure where to place:
<configuration>
<appName>gentle-shore-6874</appName>
</configuration>
here's the file from eclipse:
<?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>
<groupId>com.example</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>helloworld</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.7.v20170914</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>2.0.7</version>
<configuration>
<buildpacks>
<buildpack>heroku/exec</buildpack>
<buildpack>heroku/metrics</buildpack>
<buildpack>heroku/jvm</buildpack>
</buildpacks>
</configuration>
</plugin>
</plugins>
</build>
</project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>helloworld</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.7.v20170914</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>2.0.7</version>
<configuration>
<appName>gentle-shore-6874</appName>
<buildpacks>
<buildpack>heroku/exec</buildpack>
<buildpack>heroku/metrics</buildpack>
<buildpack>heroku/jvm</buildpack>
</buildpacks>
</configuration>
</plugin>
</plugins>
</build>
</project>

Spring boot application as dependency

My problem is that I have a multi module maven build where one part is generated by swagger as a spring boot application.
The second module should extend on the code generated and finally started.
When I compile with maven the second project does not find the classes in the generated code. I checked the jar and the class files end up in a BOOT-INF directory when building the jar.
I suspect that this is the problem. What is the best solution to compile my code.
the parent pom
<?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>
<parent>
<groupId>com.xxx</groupId>
<artifactId>applications</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>project1-connector</name>
<artifactId>project1-connector</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<scm>
<developerConnection>scm:git:ssh://git#xxx.com:7999/bla/project1-java-repo.git</developerConnection>
</scm>
<properties>
<majorVersion>1</majorVersion>
<minorVersion>0</minorVersion>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<language>spring</language>
<configurationFile>${project.basedir}/src/main/resources/apiConfig.json</configurationFile>
<output>${project.basedir}/project1-api</output>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<module>project1-api</module>
<module>project1-backend</module>
</modules>
project1-api generated 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx</groupId>
<artifactId>project1-api</artifactId>
<packaging>jar</packaging>
<name>project1-api</name>
<version>1.0.1</version>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<springfox-version>2.7.0</springfox-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!--SpringFox dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
</dependencies>
</project>
project1-backend pom.xml
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.xxx</groupId>
<artifactId>project1-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>project1-backend</name>
<description>Project1 Connection</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>9</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.xxx</groupId>
<artifactId>project1-api</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
As stated here:
https://happilyblogging.wordpress.com/2017/07/31/using-spring-boot-application-as-dependency-in-another-spring-boot-application-project/
The problem is in the generated pom.xml.
If I add the configuration part to the project1-api spring-boot plugin part, it works.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>

AspectJ module dependency with Maven - How get working the Inter-type declarations methods of a dependency module

This is my situation:
I have a maven project my-project-aj-dependency composed by two jar modules:
my-project-aj-dependencyJarWithAJ (where I have an Inter-type declaration, see the ahah() method below inside the aspect AppWithAj_Ahah.aj)
my-project-aj-dependencyJarWithoutAJ
My problem is that I would like to use some declared method defined in the aspect of the first module inside the second module, but probably I missed something.
My poms configuration is the following:
Maven project pom (my-project-aj-dependency):
<?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">
<name>MyProjectAjDependency</name>
<modelVersion>4.0.0</modelVersion>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependency</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<!-- <module>TestMaven-ejb</module> -->
<module>my-project-aj-dependencyJarWithAJ</module>
<module>my-project-aj-dependencyJarWithoutAJ</module>
</modules>
<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<aspectj.version>1.8.9</aspectj.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependencyJarWithAj</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependencyJarWithoutAj</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
</plugins>
</pluginManagement>
</build>
</project>
Maven module 1 pom (my-project-aj-dependencyJarWithAJ):
<?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>
<parent>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependency</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependencyJarWithAJ</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>my-project-aj-dependencyJarWithAJ</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<!--
Have to use version 1.2 since version 1.3 does not appear to work
with ITDs
-->
<version>1.2</version>
<dependencies>
<!--
You must use Maven 2.0.9 or above or these are ignored (see
MNG-2972)
-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Maven module 2 pom (my-project-aj-dependencyJarWithoutAJ):
<?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>
<parent>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependency</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependencyJarWithoutAJ</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>my-project-aj-dependencyJarWithoutAJ</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependencyJarWithAj</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<!--
Have to use version 1.2 since version 1.3 does not appear to work
with ITDs
-->
<version>1.2</version>
<dependencies>
<!--
You must use Maven 2.0.9 or above or these are ignored (see
MNG-2972)
-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Where AppWithAj.java is:
package org.my.project.aj.dependencyJarWithAJ;
public class AppWithAj {
public static void main( String[] args ){
System.out.println( "Hello World!" );
}
}
and AppWithAj_Ahah.aj is:
package org.my.project.aj.dependencyJarWithAJ;
public aspect AppWithAj_Ahah {
public String AppWithAj.ahah(){
return "Ahahahah!";
}
}
and finally App.java is:
package org.my.project.aj.dependencyJarWithoutAJ;
import org.my.project.aj.dependencyJarWithAJ.AppWithAj;
public class App {
public static void main( String[] args ) {
System.out.println( "Hello World! " + new AppWithAj().ahah());
}
}
Your solution is way too complicated:
The AspectJ (AJ) module needs the AJ Maven plugin and a dependency on aspectjrt. So far, so good.
But the declared aspect only affects a class within its own module, extending it via ITD. So there is no need to use the AJ compiler on the pure Java module which only calls a method from the AJ module. It is irrelevant that the called method was created by ITD, to the other module it looks just like normal Java.
Consequently, all the non-AJ module needs is a normal dependency on the AJ module because it uses one of its classes. The AJ runtime dependency is transitive and should be used automatically.
Update:
You asked for POMs, here they are.
Root POM:
<?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.madx</groupId>
<artifactId>my-project-aj-dependency</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MyProjectAjDependency</name>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.source-target.version>1.7</java.source-target.version>
<aspectj.version>1.8.9</aspectj.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependencyJarWithAj</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependencyJarWithoutAj</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.source-target.version}</source>
<target>${java.source-target.version}</target>
<!-- IMPORTANT -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<!--<showWeaveInfo>true</showWeaveInfo>-->
<source>${java.source-target.version}</source>
<target>${java.source-target.version}</target>
<Xlint>ignore</Xlint>
<complianceLevel>${java.source-target.version}</complianceLevel>
<encoding>${project.build.sourceEncoding}</encoding>
<!--<verbose>true</verbose>-->
<!--<warn>constructorName,packageDefaultMethod,deprecation,maskedCatchBlocks,unusedLocals,unusedArguments,unusedImport</warn>-->
</configuration>
<executions>
<execution>
<!-- IMPORTANT -->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<modules>
<module>my-project-aj-dependencyJarWithAJ</module>
<module>my-project-aj-dependencyJarWithoutAJ</module>
</modules>
</project>
Module with AspectJ:
<?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>
<parent>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependency</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>my-project-aj-dependencyJarWithAJ</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
</dependencies>
</project>
Plain Java module:
<?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>
<parent>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependency</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>my-project-aj-dependencyJarWithoutAJ</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>org.my.project.aj.dependencyJarWithoutAJ.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.madx</groupId>
<artifactId>my-project-aj-dependencyJarWithAj</artifactId>
</dependency>
</dependencies>
</project>
Please note: I have added the Exec Maven plugin just for demo purposes, so you can do something like this:
mvn clean install
mvn -pl my-project-aj-dependencyJarWithoutAJ exec:java
Then you should see something like this on the console:
(...)
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) # my-project-aj-dependencyJarWithoutAJ ---
Hello World! Ahahahah!
Remove Exec Maven from both the root and the plain Java POMs in order to get even shorter POMs.
I got it working with this pom configuration:
Project 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">
<name>abc</name>
<modelVersion>4.0.0</modelVersion>
<groupId>com.madx</groupId>
<artifactId>abc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>abc1</module>
<module>abc2</module>
</modules>
<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<aspectj.version>1.8.9</aspectj.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.madx</groupId>
<artifactId>abc1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.madx</groupId>
<artifactId>abc2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins />
</pluginManagement>
</build>
</project>
Pom of the first module:
<?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>
<parent>
<groupId>com.madx</groupId>
<artifactId>abc</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.madx</groupId>
<artifactId>abc1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>abc1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.9</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<!--
Have to use version 1.2 since version 1.3 does not appear to work
with ITDs
-->
<version>1.2</version>
<dependencies>
<!--
You must use Maven 2.0.9 or above or these are ignored (see
MNG-2972)
-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Pom of the second module:
<?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>
<parent>
<groupId>com.madx</groupId>
<artifactId>abc</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.madx</groupId>
<artifactId>abc2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>abc2</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.madx</groupId>
<artifactId>abc1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<!--
Have to use version 1.2 since version 1.3 does not appear to work
with ITDs
-->
<version>1.2</version>
<dependencies>
<!--
You must use Maven 2.0.9 or above or these are ignored (see
MNG-2972)
-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here I show it working: AspectJ module dependency with Maven
Edit:
It seems that if the nonAj project doesn't have a AspectJ nature it warns you near the .aj defined methods (although it works fine if you simply launch it, for eclipse it is not an error, by the way this not allow you to use the autocomplete ad fills the code with wanings...). This is the snapshot:

maven module referencing itself during install command

When I run maven install I get following message -
Failed to execute goal on project Ret: Could not resolve dependencies
for project com.software.org:Ret:jar:1.0-SNAPSHOT: Could not find
artifact com.software.org:Ret:jar:1.0
Here's my pom.xml file:
<?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.software.nagibator</groupId>
<artifactId>Ret</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<compiler>1.8</compiler>
</properties>
<dependencies>
<dependency>
<groupId>com.nag.software</groupId>
<artifactId>SpringContainer</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.187</version>
</dependency>
<dependency>
<groupId>com.software</groupId>
<artifactId>nag</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.software.org</groupId>
<artifactId>SpringProxyProvider</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${compiler}</source>
<target>${compiler}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>

Maven appears to be ignoring source and target in webapp

I'm getting "Generated servlet error:|try-with-resources is not supported in -source 1.5". 1.5 is maven's default according to another question on the topic, but I thought I had fixed that in my pom.xml -
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sspo</groupId>
<artifactId>sspo-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>website</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>website</name>
<properties>
<jetty.version>9.0.5.v20130815</jetty.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<dependencies>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sspso</groupId>
<artifactId>com.sspo.package1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sspo</groupId>
<artifactId>com.sspo.package2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Other packages in the project work fine with 1.7, as seen in the parent pom -
<?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.sspo</groupId>
<artifactId>sspo-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>sspo-parent</name>
<modules>
<module>try-with-resources-works-here</module>
<module>and-here</module>
<module>even-in-this-one</module>
<module>website</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
</project>
Ultimately, I think the question is probably "what have I done wrong that maven is ignoring the source and target specifications?" There are similar questions out there, but the ones I've seen are either not solved or suggest things that exist in my pom.
Any help would be appreciated.
Jetty is using 1.5 source and target args by default for JSP compilation. See Jetty embedded and JSP compilation to 1.7? for pointers and info on switching Jetty to use 1.7

Categories