I recently noticed Scala compiler warnings that maven was generating that looked like this:
[WARNING] warning: there were 4 deprecation warning(s); re-run with -deprecation for details
[WARNING] warning: there were 3 feature warning(s); re-run with -feature for details
[WARNING] two warnings found
It was not immediately apparent to me how to follow the warning's instructions so I could get details on how to change my code.
Just to make it clearer from Philip's answer (as specified on the plugin page), add the following to your pom.xml file:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
...
<configuration>
<args>
<arg>-deprecation</arg>
<arg>-feature</arg>
</args>
</configuration>
</plugin>
It turns out that these two instructions are coming from the Scala compiler and so what needs to happen under the covers is for scalac to be called with -deprecation or -feature as described here:
http://www.scala-lang.org/files/archive/nightly/docs-2.10.3/manual/html/scalac.html
(actually I never saw the -feature option explained anywhere but I was able to specify it as follows)
I'm using the scala-maven-plugin and compiling with scala:compile described here:
http://davidb.github.io/scala-maven-plugin/compile-mojo.html
The relevant parameter is described here:
http://davidb.github.io/scala-maven-plugin/compile-mojo.html#addScalacArgs
So, two maven commands that I found helpful were:
mvn clean compile -DaddScalacArgs=-deprecation
mvn clean compile -DaddScalacArgs=-feature
Related
I reinstalled between jdk-8 and jdk-12, the building process shows different errors but both failed. And both are showing in the log that the bcel package is missing as the first error.
I've set JAVA_HOME in both jdk with the corresponding value;
sh build.sh -Ddist.dir=~/tmp/ant dist
this is the code I get from the org document for building.
Loading source files for package org.apache.tools.tar...
Loading source files for package org.apache.tools.zip...
Constructing Javadoc information...
/home/uppdev/tmp/ant/src/main/org/apache/tools/ant/filters/util/JavaClassHelper.java:23: error: package org.apache.bcel.classfile does not exist
import org.apache.bcel.classfile.ClassParser;
^
/home/uppdev/tmp/ant/src/main/org/apache/tools/ant/filters/util/JavaClassHelper.java:24: error: package org.apache.bcel.classfile does not exist
import org.apache.bcel.classfile.ConstantValue;
:
:
:
Building index for all the packages and classes...
Building index for all classes...
Generating /home/uppdev/tmp/ant/build/javadocs/help-doc.html...
Note: Custom tags that could override future standard tags: #todo. To avoid potential overrides, use at least one period character (.) in custom tag names.
26 errors
100 warnings
BUILD FAILED
/home/uppdev/tmp/ant/build.xml:1012: The following error occurred while executing this line:
/home/uppdev/tmp/ant/build.xml:1520: Javadoc returned 1
Total time: 20 seconds
If this is for ant 1.10.2 then I can provide info:
JDK8 returns an error for missing references in javadocs (see https://bugs.openjdk.java.net/browse/JDK-8224266) which can be maded non-fatal by passing -Xdoclint:none to javadoc.
ant 1.10.2 removed this flag together with the configure param withDoclint which made builds fail if the optional dependencies were not found.
A workaround is to add additionalparam="-Xdoclint:none" to the <javadoc ...> tag in the <target name="javadocs" in build.xml before building.
Fixed part of 1.10.2:
<target name="javadocs" depends="check-javadoc"
description="--> creates the API documentation" unless="javadoc.notrequired">
<mkdir dir="${build.javadocs}"/>
<javadoc additionalparam="-Xdoclint:none"
useexternalfile="yes"
destdir="${build.javadocs}"
failonerror="true"
author="true"
version="true"
locale="en"
windowtitle="${Name} API"
doctitle="${Name}"
maxmemory="1000M"
verbose="${javadoc.verbose}">
I am running into the following error when trying to run ant:
Problem: failed to create task or type runtarget
I am building on a mac 10.8.3.
Prior research has suggested that I add ant-contrib-0.3.jar to my ANT_HOME installation directory, which I have done (that had actually gotten rid of another 'failed to create task or type' error)
I used ant-contrib-0.3.jar because research suggested that this jar is mapped to the line:
< taskdef resource="net/sf/antcontrib/antcontrib.properties" />
which is in the build.xml file I am using.
The project builds on windows machines ( I even got it to build using https://code.google.com/p/winant/ ) but am trying to get it built on a mac. I am thus not looking to change the build.xml file.
An example of the run target line is:
<target name="setPASProps" depends="" description="setup the properties">
<property name="systemname" value="PAS"/>
<runtarget target="setSystemProps"/>
</target>
Here is some info from running ant -diagnostics
-------------------------------------------
ANT PROPERTIES
-------------------------------------------
ant.version: Apache Ant(TM) version 1.8.2 compiled on June 20 2012
ant.java.version: 1.7
Is this the Apache Harmony VM? no
Is this the Kaffe VM? no
Is this gij/gcj? no
ant.core.lib: /usr/share/ant/lib/ant.jar
ant.home: /usr/share/ant
-------------------------------------------
ANT_HOME/lib jar listing
-------------------------------------------
ant.home: /usr/share/ant
ant-antlr.jar (5756 bytes)
ant-contrib-0.3.jar (17708 bytes)
ant-jmf.jar (6745 bytes)
ant-junit.jar (102350 bytes)
ant-junit4.jar (7126 bytes)
ant-launcher.jar (12321 bytes)
ant-swing.jar (7563 bytes)
ant-testutil.jar (15198 bytes)
ant.jar (1937098 bytes)
Thanks !
It would be helpful if you posted your build.xml too.
You usually get this error if Ant sees a task, but there's a problem with the definition.
Here's my recommendation:
In your project create a directory antlib/ant-contrib.
Download this zip file. Ant-contrib is a wee bit strange is that there is a separate jar for C compiling and for all of the other Ant tasks. The latest version is 1.0b3. When you unzip this zip file, you will see ant-contrib-1.0b3.jar inside this folder.
Put that ant-contrib-1.0b3.jar inside the antlib/ant-contrib folder.
Now, in your build.xml, use the following <taskdef/>:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${basedir}/antlib/ant-contrib"/>
</classpath>
</taskdef>
Make sure this is not inside a target. You want this to be executed before any targets are executed.
I like doing the definition this way because the Ant Contrib jar file becomes part of my project, and anyone who needs to run my project will not have to manually install the Ant Contrib jar before they can use my project.
Take a look at your build.xml and see where that <Runtarget> task is being used. I've never used it, and the documentation for this task is so clear and helpful. Actually, I'm not even sure if it works. If you are still having problems, you try to see if you can remove the defined <target/> that contains this task, and see if that gets rid of the issue.
Removed ant-contrib-0.3.jar and added ant-contrib-1.0b3.jar and ant-contrib.jar to my ANT_HOME directory since these are the jars installed with https://code.google.com/p/winant/ (and it was working on windows machines).
This did the trick.
I'm compiling many legacy Java code probably written with Java1.3 and I got tons of errors like this:
Copydir.java:128: warning: as of release 5, 'enum' is a keyword, and may not be used as an identifier
[javac] (use -source 5 or higher to use 'enum' as a keyword)
[javac] Enumeration enum = filecopyList.keys();
It's too time consuming to replace each instance of enum with _enum so I added source="1.3" in ant javac task as below (based on examples from http://ant.apache.org/manual/Tasks/javac.html). But I still got the same compile error. I've tried to change source = 1.4,1.5, and still same error.
<javac srcdir="${src.dir}"
destdir="${build.classes}"
debug="true" debuglevel="lines,vars,source"
source="1.3"
deprecation="off"
optimize="on">
What is the right way to tell comiler that the source is written in 1.3, but I want to compile it to run in 1.6? I'm using jdk1.6.0.26 and ant 1.8.2
That's a warning, not an error. Unless there are other errors in the build that should work just fine.
After migrating to Mavent 3.0.3 Parent poms in several Projects cannot be resolved anymore.
The Projects are structured in a default manner, so I set
parent.relativePath to "../pom.xml"
superpom (located in repository)
|-rootpom (located locally: no error)
|-|-parentpom (located locally: error resolving parent)
|-|-|-module1 (located locally: error resolving parent)
|-|-|-module2 (located locally: error resolving parent)
|-|-|-module3 (located locally: error resolving parent)
|-|-|-module4 (located locally: error resolving parent)
The Error...
Non-resolvable parent POM for myGroup:myArtifactId:1.0: Failure to
find myGroup:myParentArtifactId:1.0 in
http://myRepo.net/archiva/repository/maven2 was cached in the local
repository, resollution will not be reattempted until the update
interval of maven2 has elapsed or updates are forced and
'parent.relativePath' points at wrong local POM #
myGroup:myParentArtifactId:1.0, C:\myProjectDir\parent\pom.xml, line
x, column y -> [Help 2]
... seems to indicate that the pom was searched for in the repository, so I wonder why the pom was not found locally before looked elsewhere.
I have read that maven3 might get confused when several repositories are defined in the settings.xml, but that was always when searching for a pom inside repositories and not locally.
update
Up until now we did execute the maven build on the parent-project level (parentpom) - a fact which I did not know was important, since maven2 completed successfully until now.
When using maven3 this seems to be of importance.
When executing maven3 on the root-project level (rootpom) the build finishes successfully.
So my immediate problem is solved.
Since I don't necessarily want to answer my own question maybe
someone can explain why maven3 behaves this way now or why the old
approach was wrong.
Make sure you Double-Check that the version you refer to in the child-pom is the same as that in the parent-pom. For me, I'd bumped version in the parent and had it as 3.1.0.0-RELEASE, but in the child-pom, I was still referring to the previous version via relativePath, and had it defined as 2.0.0.0-SNAPSHOT. It did not make any difference if I included just the parent directory, or had the "pom.xml" appended to the directory:
<parent>
<artifactId>eric-project-parent</artifactId>
<groupId>com.eric.common</groupId>
<!-- Should be 3.1.0.0-RELEASE -->
<version>2.0.0.0-SNAPSHOT</version>
<relativePath>
../../EricParentAsset/projects/eric-project-parent</relativePath>
</parent>
Here is answer to your question.
By default maven looks in ../pom.xml for relativePath. Use empty <relativePath/> tag instead.
'parent.relativePath' points at wrong local POM #
myGroup:myParentArtifactId:1.0, C:\myProjectDir\parent\pom.xml
This indicates that maven did search locally for the parent pom, but found that it was not the correct pom.
Does pom.xml of parentpom correctly define the parent pom as the pom.xml of rootpom?
Does rootpom folder contain pom.xml as well as the paretpom folder?
I had the same problem. My project layout looked like
\---super
\---thirdparty
+---mod1-root
| +---mod1-linux32
| \---mod1-win32
\---mod2-root
+---mod2-linux32
\---mod2-win32
In my case, I had a mistake in my pom.xmls at the modX-root-level. I had copied the mod1-root tree and named it mod2-root. I incorrectly thought I had updated all the pom.xmls appropriately; but in fact, mod2-root/pom.xml had the same group and artifact ids as mod1-root/pom.xml. After correcting mod2-root's pom.xml to have mod2-root specific maven coordinates my issue was resolved.
You need to check your relative path, based on depth of your modules from parent if module is just below parent then in module put relative path as:
../pom.xml
if its 2 level down then
../../pom.xml
Please check in logs if you have http.HttpWagon$__sisu1:Cannot find 'basicAuthScope' this error or warning also, if so you need to use maven 3.2.5 version, which will resolve error.
<parent>
<groupId>com.test.vaquar.khan</groupId>
<artifactId>vk-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../projectname/pom.xml</relativePath>
</parent>
Add following line in parent
<relativePath>../projectname/pom.xml</relativePath>
You need relative path if you are building from local parent pom not available in nexsus, add pom in nexus then no need this path
For me, it works when I double checked the parent´s "group ID" and "artifact ID" that in my case were the wrong ones and that was the problem.
(See edits below.)
The reason I can't just use the classpath, is because I need to manage some non-java libraries, and I'm compiling a non-java project.
I'm trying to use maven dependencies in an antrun call, following the documentation on the maven site:
http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html
At the bottom of the page:
<property name="mvn.dependency.jar"
refid="maven.dependency.my.group.id:my.artifact.id:classifier:jar.path"/>
<echo message="My Dependency JAR-Path: ${mvn.dependency.jar}"/>
I can't make this work no matter how I try. I've tried ${} around the refid contents, I've tried colons, periods, etc.. as separators in every way I can think of.
Can anyone tell me what that refid should really look like for some common dependency?
EDIT:
Thanks for your reply.
Using your example SingleShot, I have the following:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>create-messages</id>
<phase>compile</phase>
<configuration>
<tasks>
<property name="build.compiler" value="extJavac"/>
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<property name="log4j.jar" refid="log4j:log4j:jar"/>
<echo message="Where is the Log4J JAR?: ${log4j.jar}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
</plugin>
And here's what I get when run mvn compile:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Chat Component
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
Downloading: http://<redacted>/content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.pom
2K downloaded
Downloading: http://<redacted>/content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.jar
358K downloaded
[INFO] [antrun:run {execution: create-messages}]
[INFO] Executing tasks
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing ant tasks
Embedded error: Reference log4j:log4j:jar not found.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Fri Oct 16 14:54:19 PDT 2009
[INFO] Final Memory: 7M/80M
[INFO] ------------------------------------------------------------------------
EDIT (2):
Looking at the sourcecode linked I decided to run "mvn -X compile" and grep for "Storing", which turns up a bunch of log output where things are getting stored.
Of interest are the facts that the dependency I'm explicitly specifying isn't showing in the list, and, that when I switch to a key based on one of the entries I do see, I still get the error.
Based on the code that SingleShot linked to, and random poking until it worked, here's how I got this problem "working", (I say in quotes because it feels very tenuous.)
Here's the way to make it properly work:
<property name="log4j_location"
value="${maven.dependency.log4j.log4j.jar.path}"/>
<echo message="${log4j_location}"/>
Some important things to note: You cannot use the maven dependency as a refid in setting the ant property. You have to use ${} to get the maven var value.
It appears that the dependency must be in the top-level dependency list, making log4j a dependency of the antrun plugin does not expose it to the plugin in anyway that I can see.
All of the path separators are dots (.), no colons (:) which is why I ultimately checked my own answer as correct.
Soapbox:
I would highly recommend anyone considering Maven use Ant with maven plugins or, even better, use Ant with Ivy instead.
This particular problem is a shining example of the utterly absurd level of difficulty associated with doing anything out of the norm with maven.
I say this having implemented an entire build system based on Maven2, and having also implemented several build systems in Ant. I've used both Maven2 and Ant with complex builds involving Java, Flex/AS3, C# and C++. Maven makes sense for Java projects that have no external dependencies on projects in other languages.
Maven does address some things that aren't addressed implicitly by Ant, but with some up front planning, Ant is the much more flexible, better documented, and the less buggy tool.
If you decide to go the ant route, make sure to define a structure for your projects, figure out your dependency system (Use one).
I think you will ultimately be much happier than with Maven, as you won't spend crunch time trying to fix your build system.
As an addendum to Aaron H.'s answer above, I had to set the plugin's version to 1.3 for that to actually work. I was using it without a specific version and was getting 1.1 (where nothing seems to work).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
...
</plugin>
Without an example of what you typed into your POM its hard to say, but consider a concrete example. Let's say your POM references log4j (groupId=log4j, artifactId=log4j). I believe this is how you would reference that JAR in your Ant file:
<property name="log4j.jar" refid="maven.dependency.log4j:log4j:jar.path"/>
<echo message="Where is the Log4J JAR?: ${log4j.jar}"/>
Ideally you shouldn't have to reference specific JARs, but rather, reference the entire classpath for the appropriate scope, as the somewhat sparse documentation for the plug-in indicates.
If you still have trouble, please post the <dependency> tag for a Maven POM dependency you are using and I can try to be more specific.
I looked at the plugin's code to confirm.
This works for me.
<copy file="${javax.mail:javax.mail-api:jar}" todir="tomcat/lib" />
<copy file="${org.springframework:spring-instrument-tomcat:jar}" todir="tomcat/lib" />
<copy file="${postgresql:postgresql:jar}" todir="tomcat/lib"/>
http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html has the explanation of how to reference dependencies form the ant classpath.
There is a bug in the documentation. The path should be of the form:
<property name="mvn.dependency.jar"
value="${maven.dependency.my.group.id.my.artifact.id.classifier.jar.path}"/>
So the correct key for your log4j dependency would be:
maven.dependency.log4j.log4j.jar.path
Also note that it should be value= rather than refid=, so the full property would be:
<property name="log4j.jar"
value="${maven.dependency.log4j.log4j.jar.path}"/>
<echo message="My Dependency JAR-Path: ${log4j.jar}"/>
I have an existing ant and we planned to use (new) maven to call it. I encountered problems that I may not remember clear, but it is related to class pathes, maybe just like yours.
The problem is, the "ant" we are using daily is a shell script that sets class pathes, both on XNIX and Windows. I have not compared class pathes set by it and those available to maven, but my test showed they dont match and ant won't run with some pathes passed to it from maven.
What I am using is "exec-maven-plugin" and run ant as an external program with some arguments applied. This is sure to work but adds extra dependencies, though.