I have searched over SO and Internet, but no success. This is what I have in short:
Multimodule project with dev and appserv profile. When dev profile is used (just mvn clean install because default=true), then load specific dependencies. One dependency is Child-A that must be loaded in Child-B. I am building always from parent POM.
I have profile defined in parent POM with activation and in Child-B I have same profile with dependencies.
This is my parent POM:
<project ..>
<groupId>com.organisation</groupId>
<artifactId>project-name</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>child-b</module>
<module>child-a</module>
</modules>
<properties>
<javax.ws.rs.version>2.0</javax.ws.rs.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- project dependencies -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>child-a</artifactId>
<version>${project.version}</version>
</dependency>
<!-- build dependencies -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>child-a</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
<profile>
<id>app-server</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env</name>
<value>app-server</value>
</property>
</activation>
</profile>
</profiles>
</project>
My Child-B module that calls Child-A, the IDE as well when building Child-B doesn't see Child-A's classes.
<project ..>
<parent>
<groupId>com.organisation</groupId>
<artifactId>project-name</artifactId>
<version>1.0</version>
</parent>
<artifactId>child-b</artifactId>
<packaging>jar</packaging>
<profiles>
<profile>
<id>dev</id>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>child-a</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>app-server</id>
<dependencies>
...
</dependencies>
</profile>
</profiles>
<dependencies>
...
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
...
</dependencies>
</project>
I don't see what is wrong here and can't understand where the problem is, why Child-B doesn't take Child-A as dependency. In parent POM inside profile I have tried to remove the dependencyManagement, but the result was still same - Child-A not seen in Child-B module. Apparently without the profiles everything was working fine.
In Child-b you put a dependency to child-b instead of a dependency to child-a
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>child-b</artifactId>
</dependency>
instead of
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>child-a</artifactId>
</dependency>
Related
I have problem with relations of pom, with dependency versions etc. Below my structure:
My MAIN pom, which gives me the order to build of all projects
<groupId>com.xyz</groupId>
<artifactId>yxz</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>xyz</name>
<modules>
<module>commons</module>
<module>projectA</module>
<module>ProjectB</module>
...
<module>ProjectX</module>
</modules>
COMMONS pom, it is designed to have common dependencies and properties, without any parent
<groupId>com.xyz</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
<name>commons</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.version>3.8.1</maven.compiler.version>
<java.version>11</java.version>
<lombok.version>1.18.24</lombok.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
ProjectA pom, include commons dependency, with spring-boot in parent,
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xyz</groupId>
<artifactId>projectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projectA</name>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
<dependency>
some dependencies from org.springframework.cloud
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
...
</build>
ProjectB pom, include commons dependency, with custom framework in parent,
<parent>
<groupId>com.customframework</groupId>
<artifactId>custom.framework</artifactId>
<version>1.8.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xyz</groupId>
<artifactId>projectB</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projectB</name>
<properties>
<java.version>11</java.version>
<customeframework.feign.version>10.12</customeframework.feign.version>
</properties>
<dependencies>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
<version>11.8</version>
</dependency>
other feign dependecies with 11.8 version
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.customframework</groupId>
<artifactId>custom.framework.feign</artifactId>
<version>${customeframework.feign.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
...
</build>
When i build my all projects then:
projectA has lombok with version from springframework.cloud dependency management, not with version from commons
ProjectB has similar problem with feign, if i add feign dependency with version 11.8, maven use version from customframework (version 9.x)
What i want to do:
I tried add bom pom file, like next module to MAIN pom but how should i add it when i have other dependency management from springframework.cloud
i have 5-6 projects with spring boot parent, some with quarqus and with custom framework and i want configure all dependency versions and parent spring boot versions in one file
If you want to have the same dependencies in all modules then how about you define <dependencyManagement> with all required BOMs and versions in one place (e.g. in commons module)?
It won't bother the modules if they don't include some of the dependencies but it will make sure that all the modules have the same dependencyManagement rules.
Read the mongodb user name and password from settings.xml based on profile selection in pom.xml.
I am not getting idea how to do. Can any one give example.
I followed reference link
https://examples.javacodegeeks.com/enterprise-java/spring/loading-environment-specific-configurations-properties-spring-using-maven-profiles-xml-settings-file-example/
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">//here showing error
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>Spring Maven Properties Example Code</name>
<properties>
<!-- Generic properties -->
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<resource.directory>src/main/resources</resource.directory>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.11</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</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-data-mongodb</artifactId>
</dependency>
<!-- Test Artifacts -->
</dependencies>
<profiles>
<profile>
<id>dev</id>
<!-- Dev Env. Properties -->
<properties>
<profile.name>${profile.name}</profile.name>
<!-- Database Properties -->
<db.driverClass>${db.driverClass}</db.driverClass>
<db.connectionURL>${db.connectionURL}</db.connectionURL>
<db.username>${db.username}</db.username>
<db.password>${db.password}</db.password>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<!-- Test Env. Properties -->
<properties>
<profile.name>${profile.name}</profile.name>
<!-- Database Properties -->
<db.driverClass>${db.driverClass}</db.driverClass>
<db.connectionURL>${db.connectionURL}</db.connectionURL>
<db.username>${db.username}</db.username>
<db.password>${db.password}</db.password>
</properties>
</profile>
<profile>
<id>prod</id>
<!-- Prod Env. Properties -->
<properties>
<profile.name>${profile.name}</profile.name>
<!-- Database Properties -->
<db.driverClass>${db.driverClass}</db.driverClass>
<db.connectionURL>${db.connectionURL}</db.connectionURL>
<db.username>${db.username}</db.username>
<db.password>${db.password}</db.password>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- specify UTF-8, ISO-8859-1 or any other file encoding -->
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
<resources>
<!-- Placeholders that are found from the files located in the configured
resource directories are replaced with the property values found from the
profile specific configuration file. -->
<resource>
<directory>${resource.directory}</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
application.properites
db.connectionURL=${db.connectionURL}
db.username=${db.username}
db.password=${db.password}
I put the settings.xml file in current project dir.
settings.xml
<profiles>
<profile>
<id>dev</id>
<!-- Dev Env. Properties -->
<properties>
<profile.name>dev</profile.name>
<!-- Database Properties -->
<db.driverClass>com.mysql.jdbc.Driver</db.driverClass>
<db.connectionURL>jdbc:postgresql://localhost:5432/springbootdb</db.connectionURL>
<db.username>postgres</db.username>
<db.password>postgres</db.password>
</properties>
</profile>
</profiles>
MainApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Here i am testing for postgres weather it is working or not but showing error in pom.xml file here
<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">
the error is
Project build error:
Resolving expression: '${db.password}': Detected the following recursive expression cycle in 'db.password': [db.password]
I want to test scenarios for postgres and monngodb.
Help me out..
If you are using Spring Boot, the syntax for Maven filtering is slightly different. You should use #propery# instead of ${property}. So you should change your application.properties as follows :
db.connectionURL=#db.connectionURL#
db.username=#db.username#
db.password=#db.password#
This blog gives more details
After Tomcat starts Magnolia, I always get the following error:
17:04:36.781 [localhost-startStop-1] ERROR info.magnolia.module.ModuleManagerImpl - Can't start module ui-framework
com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: com/vaadin/data/util/converter/Converter$ConversionException
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2216) ~[guava-23.1-jre.jar:?]
And later when I request the admin page, I keep getting these errors.
INFO: Requested resource [/VAADIN/themes/valo/styles.css] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.
Jan 23, 2018 12:50:50 PM com.vaadin.server.VaadinServlet serveStaticResourcesInVAADIN
INFO: Requested resource [/VAADIN/themes/valo/favicon.ico] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.
Amongst other things, I've included everything I think I need in the dependencies for the UI framework:
<project>
<!-- ... -->
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-framework</artifactId>
<version>${magnoliaUiVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-admincentral</artifactId>
<version>${magnoliaUiVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-contentapp</artifactId>
<version>${magnoliaUiVersion}</version>
</dependency>
</project>
Edit 1:
So I've found that magnolia-resources is version 2.4 in the Magnolia Travel Demo. When you run it with this version (and Magnolia 5.6.1 Core) the login screen doesn't display the Magnolia logo. When I upgraded to version 2.6, the Magnolia logo appeared.
Edit 2:
I'm now able to login, and the admincentral is stuck on loading. After a few seconds, the following message pops up:
Failed to load the widgetset: ./../VAADIN/widgetsets/info.magnolia.widgetset.MagnoliaWidgetSet/info.magnolia.widgetset.MagnoliaWidgetSet.nocache.js?1516882029507
POM below:
<?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><!-- hidden --></groupId>
<artifactId><!-- hidden --></artifactId>
<name><!-- hidden --></name>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<description><!-- hidden --></description>
<properties>
<magnoliaVersion>5.6.1</magnoliaVersion>
<magnoliaUiVersion>5.6.1</magnoliaUiVersion>
<magnoliaDamVersion>2.3</magnoliaDamVersion>
<magnoliaPasswordManagerVersion>1.2</magnoliaPasswordManagerVersion>
<magnoliaImagingVersion>3.4</magnoliaImagingVersion>
<magnoliaCategorizationVersion>2.6</magnoliaCategorizationVersion>
<magnoliaTemplatingVersion>1.2</magnoliaTemplatingVersion>
<magnoliaResourcesVersion>2.6</magnoliaResourcesVersion>
<magnoliaFormVersion>2.4</magnoliaFormVersion>
<magnoliaSiteVersion>1.2</magnoliaSiteVersion>
<vaadinVersion>8.1.5</vaadinVersion>
<mavenCompilerVersion>3.6.1</mavenCompilerVersion>
<tomcat7Version>2.2</tomcat7Version>
</properties>
<dependencyManagement>
<dependencies>
<!-- info.magnolia -->
<dependency>
<groupId>info.magnolia</groupId>
<artifactId>magnolia-project</artifactId>
<version>${magnoliaVersion}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>info.magnolia.ui</groupId>
<artifactId>magnolia-ui-project</artifactId>
<version>${magnoliaUiVersion}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>info.magnolia.cache</groupId>
<artifactId>magnolia-cache-core</artifactId>
<version>${magnoliaVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.site</groupId>
<artifactId>magnolia-site</artifactId>
<version>${magnoliaSiteVersion}</version>
</dependency>
<!-- info.magnolia.dam -->
<dependency>
<groupId>info.magnolia.dam</groupId>
<artifactId>magnolia-dam-templating</artifactId>
<version>${magnoliaDamVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.dam</groupId>
<artifactId>magnolia-dam-jcr</artifactId>
<version>${magnoliaDamVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.dam</groupId>
<artifactId>magnolia-dam-api</artifactId>
<version>${magnoliaDamVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.dam</groupId>
<artifactId>magnolia-dam-app</artifactId>
<version>${magnoliaDamVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.dam</groupId>
<artifactId>magnolia-dam-imaging</artifactId>
<version>${magnoliaDamVersion}</version>
</dependency>
<!-- info.magnolia.imaging -->
<dependency>
<groupId>info.magnolia.imaging</groupId>
<artifactId>magnolia-imaging</artifactId>
<version>${magnoliaImagingVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.imaging</groupId>
<artifactId>magnolia-imaging-support</artifactId>
<version>${magnoliaImagingVersion}</version>
</dependency>
<!-- info.magnolia.passwordmanager -->
<dependency>
<groupId>info.magnolia.passwordmanager</groupId>
<artifactId>magnolia-module-password-manager</artifactId>
<version>${magnoliaPasswordManagerVersion}</version>
</dependency>
<!-- info.magnolia.resources -->
<dependency>
<groupId>info.magnolia.boms</groupId>
<artifactId>magnolia-external-dependencies</artifactId>
<version>${magnoliaVersion}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>info.magnolia.resources</groupId>
<artifactId>magnolia-resources</artifactId>
<version>${magnoliaResourcesVersion}</version>
</dependency>
<!-- info.magnolia.categorization -->
<dependency>
<groupId>info.magnolia.categorization</groupId>
<artifactId>magnolia-categorization</artifactId>
<version>${magnoliaCategorizationVersion}</version>
</dependency>
<!-- info.magnolia.templating -->
<dependency>
<groupId>info.magnolia.templating</groupId>
<artifactId>magnolia-templating-kit</artifactId>
<version>${magnoliaTemplatingVersion}</version>
</dependency>
<dependency>
<groupId>info.magnolia.templating</groupId>
<artifactId>magnolia-templating-essentials-models</artifactId>
<version>${magnoliaTemplatingVersion}</version>
</dependency>
<!-- info.magnolia.form -->
<dependency>
<groupId>info.magnolia.form</groupId>
<artifactId>magnolia-form</artifactId>
<version>${magnoliaFormVersion}</version>
</dependency>
<!-- com.vaadin -->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-compatibility-server</artifactId>
<version>${vaadinVersion}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
<version>${vaadinVersion}</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>magnolia.public</id>
<url>https://nexus.magnolia-cms.com/content/groups/public</url>
<snapshots />
</repository>
<!-- IF YOU NEED MODULES FROM THE ENTERPRISE VERSION, UNCOMMENT THE FOLLOWING REPOSITORY -->
<!--
<repository>
<id>magnolia.enterprise.releases</id>
<url>https://nexus.magnolia-cms.com/content/repositories/magnolia.enterprise.releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
-->
<repository>
<id>vaadin-addons</id>
<url>https://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profileName>default</profileName>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${tomcat7Version}</version>
<configuration>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${mavenCompilerVersion}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module><!-- hidden -->-webapp</module>
<module><!-- hidden -->-blossom</module>
</modules>
</project>
Any thoughts?
Please have a look at https://documentation.magnolia-cms.com/display/DOCS56/Upgrading+to+Magnolia+5.6.x. Especially part of Vaadin8 Upgrade and BOM. I believe you have to import dependency management section from BOM project.
Hope this helps,
Cheers,
I have something like this:
<profiles>
<profile> <id>a</id>
<dependencies> <dependency> <x> </dependency> </dependencies>
</profile>
<profile> <id>b</id>
<dependencies> <dependency> <y> </dependency> </dependencies>
</profile>
</profiles>
<dependencies>
<z>
</dependencies>
So profile a has a dependency x, profile b has dependency y. BOTH have dependency z. The issue is, maven puts dependency z before x or y. I need it the other way around. I need x/y to be override z.
How can I do this? My current workaround is to put the dependency of z in both the profiles like so:
<profiles>
<profile> <id>a</id>
<dependencies>
<dependency> <x> </dependency>
<dependency> <z> </dependency>
</dependencies>
</profile>
<profile> <id>b</id>
<dependencies>
<dependency> <y> </dependency>
<dependency> <z> </dependency>
</dependencies>
</profile>
</profiles>
This works but seems like there should be a better way to do it.
I want to try something new and use Dagger 2 as my DI framework. So I have the following pom and the "hello world" coffee maker classes (http://google.github.io/dagger/) in my projekt.
But when I do a mvn clean install no classes get generated. As far as I unterstood there should be a "Dagger_CoffeeShop" class generated. Hmmm ... what am I missing?
<modelVersion>4.0.0</modelVersion>
<groupId>kic</groupId>
<artifactId>xfoo</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<dependencies>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
For those using Gradle: Make sure you are referencing the Dagger dependencies as following:
compile 'com.google.dagger:dagger:2.0.2'
apt 'com.google.dagger:dagger-compiler:2.0.2'
And in the case if you are running into apt not supported, add
1) Into module app\build.gradle:
apply plugin: 'com.neenbedankt.android-apt'
2) Into project \build.gradle:
buildscript {
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
I had the same problem, only with the release version 2.0.
In my case the following two steps solved this problem:
Adding target/generated-sources/annotations to my build path
Adding <forceJavacCompilerUse>true</forceJavacCompilerUse> to the maven compiler plugin
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<dependencies>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!-- workaround for https://issues.apache.org/jira/browse/MCOMPILER-202 -->
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
</plugin>
See also:
https://github.com/google/dagger/pull/103
https://issues.apache.org/jira/browse/MCOMPILER-202
This isn't the best answer. When I used the downloaded JAR files (commented out in the POM file below) mine also wasn't generating the Dagger_ files. Once I added the repository to the POM, everything was working fine.
<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.hello</groupId>
<artifactId>hellodagger</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>hellodagger</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>sonatype</id>
<name>sonatype-repo</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2.0-SNAPSHOT</version>
<!--<scope>system</scope>-->
<!--<systemPath>${project.basedir}/dagger-2.0-20141216.223138-12.jar</systemPath>-->
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.0-SNAPSHOT</version>
<optional>true</optional>
<!--<scope>system</scope>-->
<!--<systemPath>${project.basedir}/dagger-compiler-2.0-20141216.223201-12-jar-with-dependencies.jar</systemPath>-->
</dependency>
</dependencies>
</project>