I am looking to exclude the log4j in my pom file. It is not even available in the remote repository.
I have a property with version 4.0.0 in the parent pom file.
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.3.0</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
<configuration>
<excludes>
<exclude>**/log4j*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
It simply does not work; I keep getting the message below.
Execution scala-compile-first of goal net.alchim31.maven:scala-maven-plugin:4.3.0:add-source failed: Plugin net.alchim31.maven:scala-maven-plugin:4.3.0 or one of its dependencies could not be resolved: Failure to find org.apache.logging.log4j:log4j-core:jar:2.11.2
excludes configuration section inside the scala-maven-plugin is meant for filtering resources to be compiled.
In your case log4j is a dependency (already compiled), you have to find what is pulling it in the build and exclude it from there (or setup a global dependency exclusion rule).
Related
This feels like it should be easy, so please help point me in the correct direction.
I am successfully using maven to build my java project using a Azure Pipeline. I am also successfully getting JaCoCo coverage reports.
I have a maven project with multiple modules. Below is a sample project structure. I want to exclude everything in all the sub src/test/java directories/packages.
myproject
mod1
src/main/java/...
src/test/java/...
pom.xml
mod2
src/main/java/...
src/test/java/...
pom.xml
pom.xml
I would have expected something like setting codeCoverageClassFilter to -:*.src.test.java*.*, but none of my variations have worked. What is the correct statement to exclude all these test directories?
For excluded test add next configuration in pom parent
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<configuration>
<excludes>
<exclude>com/acme/test/*</exclude>
</excludes>
</configuration>
<executions>
<!-- prepare agent for measuring integration tests -->
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
I have an API written in Swagger for which I want to generate both the Service implementation and also the client, and they have to be in separate maven modules.
I was thinking of separating them into 3 separate Maven modules (or submodules of the same parent pom).
parent
+- api
+- src/main/resources/api/service.yaml
+- client
+- service
Then in both client and service I would have the swagger-codegen-maven-plugin. This way both will be in sync and I will only maintain the service from one place. Other clients can also depend on the api artifact and generate their code from the service.yaml Swagger API definition.
My difficulty is how do I make the service and client refer to the service.yaml in another Maven dependency?
This is what I currently have in the service pom.xml, but it refers to the local resources of the service module, not to the api maven dependency.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${io.swagger.codegen.version}</version>
<executions>
<execution>
<id>api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- can this refer to another maven dependency's resources? -->
<inputSpec>${basedir}/src/main/resources/api/service.yaml</inputSpec>
<language>spring</language>
<library>spring-boot</library>
<modelPackage>com.test.model</modelPackage>
<apiPackage>com.test.api</apiPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Not sure if this is something I have to do from Maven, to refer to resources from another maven dependency, or something I have to do in the swagger plugin configuration.
The solution I managed to find is to use the maven-remote-resources-plugin. In the pom.xml of the maven project that needs to expose resources you can put:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*.yaml</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
Then in the project that needs to import them, the project needs to be referred to as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<configuration>
<resourceBundles>
<resourceBundle>group:api:version</resourceBundle>
</resourceBundles>
</configuration>
<executions>
<execution>
<phase>
generate-sources
</phase>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
where group:api:version is the group ID, artifact ID and version of the maven dependency exposing the resources.
Finally, inside the swagger-codegen-maven-plugin configuration, the yaml file can be referred to as:
<inputSpec>${project.build.directory}/maven-shared-archive-resources/api/service.yaml</inputSpec>
I am trying to use the jsonschema2pojo plugin for generating POJOs based on both schema and json sourceTypes. The configurations are specified per execution. But every time the plugin is reporting "One of sourceDirectory or sourcePaths must be provided". I am able to run it when the configuration is provided at the plugin level ( global ). But then I can only specify one sourceType.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.5.1</version>
<executions>
<execution>
<id>generate-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<outputEncoding>${project.build.sourceEncoding}</outputEncoding>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<annotationStyle>jackson2</annotationStyle>
<generateBuilders>false</generateBuilders>
<initializeCollections>true</initializeCollections>
<refFragmentPathDelimiters>#/</refFragmentPathDelimiters>
<sourceType>jsonschema</sourceType>
<targetPackage>com.company.app.integration.sabre.stub.rest</targetPackage>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
</configuration>
</execution>
<execution>
<id>generate-json</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<outputEncoding>${project.build.sourceEncoding}</outputEncoding>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<annotationStyle>jackson2</annotationStyle>
<generateBuilders>false</generateBuilders>
<initializeCollections>true</initializeCollections>
<refFragmentPathDelimiters>#/</refFragmentPathDelimiters>
<sourceType>json</sourceType>
<targetPackage>com.company.app.integration.sabre.stub.rest</targetPackage>
<sourceDirectory>${basedir}/src/main/resources/json</sourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Is there any way to have the plugin use the configuration at execution level per goal ?
Plugin version: 0.5.1
tl;dr
When running the 'compile' from Maven projects lifecycle, the plugin is considering the configuration from execution and is working as expected.
I am using Intellij and was trying to generate the pojo from Plugins -> jsonschema2pojo -> jsonschema2pojo:generate under 'Maven Projects' window. This was giving the above error and was not taking the configuration per execution.
When I run compile from the Maven Lifecycle, it is picking the configuration in the execution and is generating the files as specified.
I am not yet sure if this is a issue with the plugin or maven or if its a issue at all !!
Try moving your configuration out to the plugin level and using the parent folder (${baseDir}/src/main/resources) as the sourceDirectory.
Here's an old bug report describing the same thing:
https://github.com/joelittlejohn/jsonschema2pojo/issues/145
An existing maven pom project <packaging>pom</packaging> which currently collects and packages resources needs to be extended to validate some of the resources.
In the same project I created a java-source directory src/main/java and in there I created a small java class to validate some of the resources. In addition I configured the maven-compiler and exec-maven plugin in the pom.
The java class runs fine in the IDE but it fails when I do mvn clean install it fails because it cant find the compiled class file. This is because the compile/test-compile phase is not available for pom-packaged projects.
My questions are:
Can I modify the compiler plugin to execute (compile) in a different phase than the default compile-phase. (I tried with adding an execution tag but no success)
Why is the exec-maven plugin executed because this was defined in test phase, which according to the docs is not part of the pom-package.
Are there other possibilities to run this validation task in the pom?
Modifying the packaging from pom to jar is a political sub-optimal solution.
Yes, you can configure maven-compiler-plugin to run the compilation in the package phase of the pom packaging.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<mainClass>com.example.validate.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
I'm kinda new to maven and have encountered a problem that I can't solve on my own.
I've written a simple module to a big project that tracks git revision number, adds a timestamp and dumps these properties to a .properties file. This project is just a pom.xml file, no java classes, and one project.properties file. I wanted to add this module as a dependency to the main project pom.xml file, but it is rebuild only once (since Maven doesn't detect any changes it doesn't rebuild it again).
How do I force rebuild of this module everytime any module of the project is rebuilt? Can I do this in the project pom.xml file, or do I somehow set this in Jenkins? Or maybe I've approached this problem in a completely wrong way?
Here's the fragment of my pom.xml file:
<build>
<plugins>
<!-- enable ${timestamp} variable -->
<plugin>
<groupId>com.keyboardsamurais.maven</groupId>
<artifactId>maven-timestamp-plugin</artifactId>
<version>1.0</version>
<configuration>
<propertyName>timestamp</propertyName>
<timestampPattern>dd.MM.yyyy HH:mm</timestampPattern>
</configuration>
<executions>
<execution>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- enable JGit plugin -->
<plugin>
<groupId>ru.concerteza.buildnumber</groupId>
<artifactId>maven-jgit-buildnumber-plugin</artifactId>
<version>1.2.7</version>
<executions>
<execution>
<id>git-buildnumber</id>
<goals>
<goal>extract-buildnumber</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
</plugin>
<!-- write project properties to file -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>${basedir}/target/classes/project.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Cheers,
Jony
Okay, problem solved (thanks to deng from #maven on irc.codehaus.org). Right now i have the main pom and two modules: version-tracker and common. In the main pom I make a dependency on version-tracker, and in the common module's pom I add main pom as a parent (therefore common inherits dependency on version-tracker).
At this stage I run mvn clean package -pl :common -am and my project.properties file is updated every time. Thanks, deng :)
I still have some other problems, but this one is solved :)