I've just downloaded a sample project off the internet which had this in the pom...
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</build>
There was an error so what i did was to remove maven-compiler-plugin and then I ran the pom and it worked (i.e. the war file was created).
Why is the compiler plugin required? And what is happening here now that I have removed it? What compiler will it be using?
The maven-compiler-plugin part is needed for changing default configurations. In this case, it was to set the JDK versions to 1.5.
You can manage without it if you don't have anything to compile, or are OK with the default values (I think 1.4).
I hope this helps.
Related
I am pulling in dependencies from a parent and need most of the dependencies in there.
But I also wish to be able to exclude 2 dependencies entirely. I am not able to edit the parent
thus this needs to be excluded from my POM file. Is this even possible? I've seen examples for overrides and quite a bit of suggestion to fix the parent POM which as mentioned, I can't do at this time.
Using Maven 3.3.x
My POM file
<parent>
<groupId>com.company.stuff</groupId>
<artifactId>our-parent</artifactId>
<version>1.7</version>
</parent>
<!-- other dependencies and build and plugins -->
The parent in above pulls in following plugins which I wish to exclude entirely.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${some.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${some.version}</version>
</plugin>
Is there a way around this? Please advice. Thanks.
Tried with Thiago's suggestion, same outcome.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.version}</version>
<executions>
<execution>
<id>maven-checkstyle-plugin</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
Why not just skip the plugin executions?
You could set the skip parameter of both plugins to true.
<plugin>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<executions>
<execution>
<id>ID_AS_IN_PARENT</id> <!-- id is necessary sometimes -->
<phase>none</phase>
</execution>
</executions>
</plugin>
Using a multi-module Maven project configured in IntelliJ IDEA, I am configuring version 1.8 in the maven-compiler-plugin in the parent POM version. But I am configuring 1.5 in a certain child module.
In the parent:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
In the child:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
In Eclipse, I had this indicator:
How and/or where do we check that in IntelliJ IDEA? How do I know that the child module is compiling with the desired 1.5 Java version?
See the related answer for the relevant screenshots.
You can find the source version in the Project Structure dialog, Modules, Sources tab: Language level.
Target version is in File | Settings | Build, Execution, Deployment | Compiler | Java Compiler (Per-module bytecode version).
Is it possible to override the default name of the jar file created running the assembly:single goal? I want to add a jar with dependencies that has a non-standard name. I am using version 2.6 of the plugin.
Yes, you need to use the finalName configuration attribute. Note that you probaby also want to remove the assembly id that is appended by default to the final name, with the help of the appendAssemblyId attribute.
Sample configuration:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
...
<finalName>myFinalName</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
The proper way to do this (as mentioned on Maven JIRA tracker) is to set the build.finalName and not to use the readonly finalName plugin property. Here is an example how to get rid of both the "jar-with-dependencies" and the version, which is very useful for creating a stable name and eliminating potentially confusing existence of 2 JARs for use in README instructions:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
...
<configuration>
<appendAssemblyId>false</appendAssemblyId>
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am trying to get maven to include an empty directory which is just used for output files created by the webapp (which is why it is empty).
I have googled and the maven-resources-plugin seemed to be the best option for this, the documentation states that the property includeEmptyDirs is since 2.3 and I am using 2.4, however this seems to do nothing and so far the only way Ive managed to get the directory to create is by putting a text file into it, I dont really want to do this if Maven should be able to do this for me.
Can someone tell me what I am doing wrong? Below is my build section from the pom file:
<build>
<finalName>MyApp</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerVersion>1.7</compilerVersion>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<configuration>
<includeEmptyDirs>true</includeEmptyDirs>
</configuration>
</plugin>
</plugins>
</build>
Take a look at the maven-war-plugin which has a configuration item includeEmptyDirectories.
I am specifying:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<outputDirectory>C:\apache-tomcat-7.0.42\webapps</outputDirectory>
</configuration>
</plugin>
.
.
.
However, even though I do not specify anything in the respective children pom.xml, the war file is still being moved to that output directory.
As far as I know, pluginManagement is only there for reference from the children pom right?
Thank you for your help
By default Maven will invoke the maven-war-plugin war:war goal as part of the package phase if you specify <packaging>war</packaging> in your pom.xml
Since you have a <pluginManagement> stanza for maven-war-plugin specifying a custom <outputDirectory> in your parent pom.xml your child pom.xml will use this property when you run the package phase.
http://maven.apache.org/plugins/maven-war-plugin/usage.html