IntelliJ IDEA output directory reverts to default target - intellij-idea

Running IntelliJ IDEA (10.5.4). It is a Seam application.
In project structure --> artifacts --> Output directory, the default value is
...../proj/proj-web/target/classes.
I keep changing it to ......./proj/src/main/webapp , which means the web server reads from the same directories I'm editing and my changes are viewable immediately.
My trouble is that IntelliJ frequently reverts back to the default and it is getting annoying. Does anyone know how to make this stick. This "didn't use to happen" in earlier versions.

try uncheck "use maven output directories"

Rename the artifact, this stops it getting overwritten on maven re-import.

I think that isn't necessary to change output directory, because idea synchronizes src and output directory after make action. Or you can setup "update resources" in web server configuration.

I had the same problem and didn't want to change the "Use Maven output directories". My solution is to set the webappDirectory property of the maven-war-pluginconfiguration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>myExampleWar</warName>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
<webappDirectory>the/path/i/want/myExampleWar</webappDirectory>
</configuration>
</plugin>
For more details see:
https://maven.apache.org/plugins/maven-war-plugin/exploded-mojo.html

Related

Arquillian Shrinkwrap provide custom settings.xml file

I have set up a arquillian project and it all works fine locally but when running the maven build on our continuous integration box it fails. I managed to get to the bottom of the problem and it is because the maven user settings.xml file on the CI box actually has some server definitions (for another project) whereas locally to my machine it is the default file (with no servers defined). The tests throw a RuntimeException because the MavenResolver goes looking for settings-security.xml file which doesn't exist on the CI box.
I would prefer not to go adding the settings-security.xml and instead would like to provide the resolver with a 'empty' settings.xml file, or even better, tell it not to use one. Is this possible?
I tried the answer from this thread https://developer.jboss.org/thread/174873 which pretty much says to add the following option to the failsafe plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version><!-- or upper -->
<configuration>
<systemPropertyVariables>
<org.apache.maven.user-settings>nonExistentSetting.xml</org.apache.maven.user-settings>
</systemPropertyVariables>
</configuration>
</plugin>
If i do this and provide an xml file that doesnt exist all work fine from the command line running 'mvn clean install' but when i debug within my IDE it still fails.
Is there a way i can either:
Tell the maven resolver not to use a settings.xml / use a 'default' file
Create an empty settings.xml in my project and tell the maven resolver to use that
I did try the following line in my code to build my archive but it didnt seem to have an effect:
.addAsLibraries(Maven.configureResolver().fromFile("test-settings.xml").loadPomFromFile("pom.xml").importRuntimeDependencies().resolve().withTransitivity().asFile())
Thanks for any help,
Craig
ShrinkWrap resolver by default loads settings-security.xml from
DEFAULT_SETTINGS_SECURITY_PATH = userHome == null ? ".settings-security.xml" : userHome.concat("/.m2/settings-security.xml").replace('/', File.separatorChar);
but you can override this location by setting
System.setProperty(MavenSettingsBuilder.ALT_SECURITY_SETTINGS_XML_LOCATION,
"someDir/empty-settings-security.xml");
When alternative location (non-empty string) is provided theoretically it should skip the default location. However I am not 100% sure this method will work.

Unable to download the artifact maven-compiler-plugin from repository

I've created a maven project and wanted to change the java compiler version to 1.6 so I added the ff:
<build>
<plugins>
<plugin>
<artifactId>org.apache.maven.plugins</artifactId>
<groupId>maven-compiler-plugin</groupId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
When I run any maven goal in eclipse, it works. But when I run in terminal I got the ff errors:
Project ID: maven-compiler-plugin:org.apache.maven.plugins
Reason: POM 'maven-compiler-plugin:org.apache.maven.plugins' not found in repository: Unable to download the artifact from any repository
maven-compiler-plugin:org.apache.maven.plugins:pom:2.3.2
from the specified remote repositories:
central (http://repo1.maven.org/maven2),
apache.repo (https://repository.apache.org/content/repositories/releases),
jboss.repo.deprecated (https://repository.jboss.org/nexus/content/repositories/deprecated),
Any idea what's causing this issue?
I was able to solved this issue by updating to maven3. But my problem right now is although I specified maven-compiler-plugin version to be 2.4, I'm still seeing 2.3.2 in the log.
Your groupId and artifactId are reversed.
If Eclipse and the command line create different results, then they use different local Maven repositories. The default is in $HOME/.m2/repository/. So the first step is to find out which one (command line or Eclipse) uses a different local cache and why.
The next question is why the download failed. The usual reason is that Maven tried the download and got an error. Maven will remember the error and not try again. To force it to try again, you have to delete the folder $M2_REPO/repository/org/apache/maven/plugins/maven-compiler-plugin/2.3.2/.
Lastly, when you configure 2.4 but see 2.3.2 in the log, then you're either building the wrong project of one of the POMs of your build overwrites the version for the compiler plugin.
To avoid issues like this, use a parent POM where you keep all the versions in dependencyManagement (for dependencies) and pluginManagement (for plugins) elements. That way, you will never have to define a version in a module POM or in other projects which inherit from this one.
After installing maven 3 from a repository and added maven3 home in /etc/environment what I forgot to do is to reboot my machine, after that it worked.
My /etc/environment now looks like:
M3_HOME="/home/edward/java/apache/maven-3.0.4"
MAVEN_HOME="/home/edward/java/apache/maven-3.0.4"
M3="home/edward/java/apache/maven-3.0.4"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/edward/java/apache/maven-3.0.4"
Here's how I uninstalled and install maven 3:
http://czetsuya-tech.blogspot.com/2012/05/how-to-install-maven-3-in-ubuntu-1110.html

Release problems with Nexus + Maven + Hudson

When using the release plug-in for Maven on Hudson(1.368), I am getting an error that my distributionManagement section is missing during the deployment phase to our Nexus Maven Repository Manager. If I deploy without using release It woks just fine so should not be a misconfiguration with the server, the section or the settings.
It is worth noting that my company uses different pom files for Hudson and have named them differently. Also the settings.xml in in the individual project directories. This has never been a problem as Hudson allows for the name of the pom and the location and name of the settings file to be specified.
The reason I note the above is that when distributionManagement is moved into the regular pom.xml it does find it (but still doesn't work because its missing the username and password in the settings file). This confuses the heck out of me since for the prior parts of the release process, it uses the correct pom and settings. It just seems to forget them later on. What is going on here?
Thank you in advance.
UPDATE
It seems that the maven release plug-in spins up a new instance of maven which, it seems, is using the default pom.xml rather than our differently named pom. More testing is needed.
The answer (for any lost souls who stumble upon this question) is that maven was indeed forking out a new process which was not using the correct pom file and settings. The solution was to add a section to the pom file as thus:
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<configuration>
<goals>-f POMFILE -s SETTINGSFILE deploy</goals>
</configuration>
</plugin>
This specified those two files to the new maven process.
If I deploy without using release It woks just fine so should not be a misconfiguration with the server, the section or the settings.
Well, there is clearly a misconfiguration somewhere, be it at the Hudson level. But it will be hard to spot it without seeing the pom, the settings, the active profiles, the profiles used during the release, the Hudson setup, etc.
First step: try to reproduce the problem on the command line using the exact same configuration as Hudson.
Second step: use the Maven Help Plugin to understand and debug the issue. More specifically, the following goals:
help:active-profiles
help:effective-pom
help:effective-settings
The reason I note the above is that when distributionManagement is moved into the regular pom.xml it does find it (but still doesn't work because its missing the username and password in the settings file).
It's unclear where the distributionManagement is specified if outside the project's pom.xml (in a corporate environment, it goes typically in a corporate pom.xml, is it the case here?).
It's also unclear if you are actually providing the username and password for a server id matching the repository id of the distributionManagement.
But somehow, a wrong combination is used here. Double check what profiles/settings are active during release/deploy to spot the problem as suggested.
See also
The Maven Deploy Plugin Usage page

Maven Checkstyle Plugin - Test XREF

My maven reports are working great, all except Checkstyle and test xref. My test source is still being cross referenced at xref and not the test xref. So, when I click on the xref from within a Checkstyle report, I naturally get an error, the file isn't found. If I click on a source file, it works perfectly.
I tried testXrefLocation in the configuration to no avail. Is this by design, or am I missing a configuration?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<enableRulesSummary>false</enableRulesSummary>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<configLocation>${project.build.directory}/checkstyle.xml</configLocation>
<testXrefLocation>${project.reporting.outputDirectory}/xref-test</testXrefLocation>
</configuration>
</plugin>
mvn clean install site
In my target directory where all this stuff is generated, I have both xref and xref-test. However, my checkstyle reports for my test source code are still linked to target/xref and not target/xref-test.
Also, FYI, I am using a lot of inheritance to reduce the amount of configuration in a single Maven POM. Therefore, this plugin belongs to a parent pom which declares which plugins I want to use for testing. I have another that says I want to generate javadoc and source in addition to the compiled code.
Walter
I actually ended up removing this configuration in favor of using Sonar since it gives me much more information with a nicer UI.

Capturing the Unique Maven SNAPSHOT build number

I am looking for a way to capture the unique SNAPSHOT build number that was generated during the 'mvn deploy' phase of the build. I would like to be able to pass this version (during a Hudson build) to another process used for deploying to an application server. The key here is being able to capture the exact Maven SNAPSHOT build number, such as:
foobar-0.4-20100707.060244-11.war
I have noticed that Hudson is capturing this information if you archive the maven build artifact, but it is not clear how I can expose this variable and pass it to another job (which is what I want to do). I can see this variable in the Hudson Home directory, like so:
/hudson/jobs/JOB_NAME/builds/24/org.ace.widgets$foobar/archive/org.ace.widgets/foobar/0.4-20100707.060244-11
Any Maven and/or Hudson experts out there that have any clue how to expose the SNAPSHOT build number? Hudson is doing it?
Check out my answer to this slightly different problem where I use GMaven to access the project metadata after deploy. What they have in common is that you have to access the unique build number. So you could adapt the script so that after it has read the project meta data (after deploy) it stores the unique version in the maven properties:
pom.properties['uniqueVersion'] = uniqueVersion
If the appserver-deploy-process is also a maven plugin, access this property, otherwise store it as a file using something like this:
new File(pom.build.directory, "uniqueVersion.txt").text = uniqueVersion
Now you can pick it up from target/uniqueVersion.txt using a shell script or so.
A little bit late, but I just noticed that you have exactly the same problem I was facing. I needed to be able to deploy arbitrary build artifacts produced on a Windows box on AIX machines. The deployment process needed to be run locally on the AIX boxes. So I defined slaves on the AIX boxes that download the build artifacts from the build job that run on the Windows box. The master is on the Windows box.
To put it in short. The build job archives the necessary artifacts and triggers the deployment job with its build URL as the parameter (it is actually a "run parameter", but string would work too). The deploy job uses wget to determine the artifact URL (it searches for a artifact ID that contains certain texts, e.g. the artifact name without the version), and downloads the artifact with wget again. wget saves it without version, so that all my deployment scripts can run on the unversioned name. You can use the first step also to find out about the artifact name as well.
wget uses the remote API (xml version). If you don't want to use wget, there is a command line tool that will do the connection for you.
You can test it by appending following strings to the run URL of the build job and use the resulting URL in your webbrowser.
#to find the path (URL) of the artifact
api/xml?xpath=*/artifact[contains(fileName,"MyApp")]/relativePath/text()
#to find the path (URL) of the artifact with more than 1 string to match
#the match must identify exactly one artifact, otherwise you will
#get an error message
api/xml?xpath=*/artifact[contains(fileName,"MyApp") and contains(fileName,".ear")]/relativePath/text()
#To download the artifact
#replace $relativePath with the actual output from one of the queries above
artifact/$relativePath
Based on Sean Patrick Floyds answer, even though this question is old, I'd like to share a full code example which writes the uniqueVersion into a maven property. Please keep in mind that Maven's internals are accessed using reflection, so this may easiliy breaks up in future maven versions. I tested it against Maven 3.2.5.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>set-uniqueVersion-property</id>
<phase>deploy</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
<![CDATA[
def uniqueVersion = null;
println "Grabbing uniqueVersion...";
project.artifact.metadataList.each{
if(it.class.simpleName=='ProjectArtifactMetadata'){
def afi = it.class.superclass.superclass.getDeclaredField('artifact');
afi.accessible = true;
uniqueVersion = it.artifact.version;
}
};
project.properties['uniqueVersion'] = uniqueVersion;
println("Unique Version grabbed: $uniqueVersion");
]]>
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
If you want to use this property within other maven plugins, please make sure that their executions are made in the deploy phase after the set-uniqueVersion-property execution. If you prefer to write the unique version to a file, simply add
new File(pom.build.directory, "uniqueVersion.txt").text = uniqueVersion
as already stated by Sean Patrick.