I have one jar dependency in my java project that contains sources as well and when I run mvn compile, these java sources appear as class files in my compiled maven output :(...
How can I exclude these files.. (I only want my own compiled files in the compiled output)
I tried something like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<excludes>
<exclude>**/bv/**/*.java</exclude>
</excludes>
</configuration>
</plugin>
Played with it but they keep appearing in my maven compiled output :( ..
Any idea's ?
My understanding is that this is a normal behavior of javac that searches the whole classpath for source files to compile unless the -sourcepath option is given (and this would be the solution here).
Unfortunately, there is a Jira issue about -sourcepath not being passed to javac by the Maven Compiler Plugin (see MCOMPILER-98) but there is a workaround. So, could you please try this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArguments>
<sourcepath>${project.basedir}/src/main/java</sourcepath>
</compilerArguments>
</configuration>
</plugin>
Would the provided scope work?
From: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html:
This is much like compile, but
indicates you expect the JDK or a
container to provide the dependency at
runtime.
You can pass the -implicit:none parameter to the compiler
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-implicit:none</compilerArgument>
</configuration>
</plugin>
Related
My Project dosnt have a bin folder
Have tried the following:
D:>java -cp "Pathtolibfolder\lib*;Pathtobinfolder\bin"
org.testng.TestNG testng.xml
Any Ideas?
If you are using Maven then i would simply use the surefire plugin and run tests as part of the build:
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>RELEASE</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
...
</plugins>
Just specify the path to your testng.xml and take advantage of it if you can use this kind of configuration.
It allows for tons of parametrization and i have used it extensively in my projects.
Check out this tutorial to get a hang of it: http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html
I have a project using SwingUtilities2 which is available in Java 5 only. I'm trying to compile it using newer JDK (using Jenkins). When it comes to pure Java only I have no problems, I simply set the compile plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerVersion>${jdk.version}</compilerVersion>
<executable>${jdk.path}/bin/javac</executable>
<fork>true</fork>
</configuration>
</plugin>
Where ${jdk.path} points to Java 1.5 JDK.
When trying to add aspects, it always compiles using default jdk (1.8).
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<complianceLevel>${jdk.version}</complianceLevel>
</configuration>
</plugin>
I was trying as well setting compilerId + dependencies in maven-compiler-plugin (see: http://maven.apache.org/plugins/maven-compiler-plugin/non-javac-compilers.html), but didn't help either.
Any clues how to do it?
EDIT:
Changed Jenkins job type from Maven to Free Style and invoke it using JDK 1.5. Now compiles with aspects.
I have some classes I'm using as tests in my src/test/java folder of my project. When I run maven using the standard maven compile plugin. Those items are compiled into .class files and are included in the jar where the compiled code is packaged.
I've created these tests for myself to run within eclipse, prior to running maven and building my release. They are just sanity tests and should not be included in the build. I'd rather not put them in a seperate project, because, to me, they make sense here. How can I tell maven that I do not want it to compile/include the files in that directory?
I beleive the maven compiler plugin is generating the jar as follows:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
I understand from your comment on this answer that the "tests" aren't unit tests, but just ordinary classes that you want excluded from the final artifact? As such, your best option is to make use of the <exclude> tag with the maven-jar-plugin as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<exclude>**/yoursortoftestpackage/YourSortOfTestClass*</exclude>
</excludes>
</configuration>
</plugin>
Hope that helps!
Cheers,
Use the option of -Dmaven.test.skip will skip both compilation and execution of the tests. ( use -DskipTests just skips the test execution, the tests are still compiled)
The reference link
mvn clean install -Dmaven.test.skip
Annotation for junit #Ignore will ignore the class while building in maven.
Edit:
You can configure maven-surefire-plugin.
<project>
<build>
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
Put your custom test files in a folder src/localtest/java i think, maven will not know it is there.
I have a Maven webapp that uses the maven-compiler-plugin . A few days ago I could compile and run the app just fine, however something happened and compilation now fails with the following error:
[ERROR] Failure executing javac, but could not parse the error:
javac: -endorseddirs requires an argument
Usage: javac <options> <source files>
It has something to do with the compiler but I can't understand it. Here's my pom.xml (just the plugins):
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
</executions>
</plugin>
</plugins>
I have tried some solutions like this.
As far as I know, ${endorsed.dir} is not a standard Maven property. Have you copied this example from somewhere without replacing ${endorsed.dir} with an actual value? Or did you have this value defined elsewhere in your pom.xmlbut it has been removed?
If this is the case, Maven would treat the field as blank and I can imagine the compiler would receive no argument for the -endorseddirs parameter.
Java compiler is not able to locate property ${endorsed.dir} in you POM, Make sure it is defined in you POM. To check configuration of POM by mvn help:effective-pom, That will show actual POM after factoring all configuration.
In Maven, I have a codebase that I want to build that needs to target the 1.4 JVM. This is very easy to do in the pom, but I have one problem: The tests for this codebase use 1.5+ constructs.
Is it possible to have Maven compile/run the tests inside a 1.6 JVM, but build the main codebase to target 1.4?
Setting source to 1.6 and target to 1.4 don't work. Maven/Java don't allow this combination.
This is possible, but you need to set the parameters for testCompile rather than compile. You can specify a different target/source combination for the testCompile that you use for the compile.
So for compile you've have a target of 1.4, and testCompile 1.5 or 1.6.
Also, to run the unit tests, you can specify the jvm to use in surefire by using the jvm parameter. This would point to a 1.6 jvm.
It's been awhile since I've done this, but the plugin dependency you want is something like this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<source>1.3</source>
<target>1.3</target>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</execution>
</executions>
</plugin>
link to source
I was able to achieve what I wanted with this:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<testSource>1.6</testSource>
<testTarget>1.6</testTarget>
<target>1.4</target>
<source>1.4</source>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>