Maven 3: override command line in POM - command-line

We can override properties defined in POM using command line.
Can we somehow make the opposite effect? To override command line parameters in POM?
I have a Hudson with "-Dmaven.test.skip -DskipTests -DskipITs" in command line, and I can't change it (admin responds to requests in a month), but I want to run my tests anyway..
Thank you)

Something you might try: Change your POM to execute the tests as part of another phase in the lifecycle. I don't know how to do this off-hand, but in the worst-case you could always use <ant> to shoehorn it in. Good luck!

Overwrite the configuration for ignoring the test in the pom explicit.

Related

IntelliJ: Command Line is too Long. Shorten command line for... in SBT project

When I try to run my app, IntelliJ has just started to tell me
"Command Line is too Long. Shorten command line for my_app or also for Application default configuration."
the my_app is a blue link which leads to an "Edit Configuration" window, automatically selecting and highlighting a dropdown for class path shortener. I select the suggested options, but no change.
I have no idea what this means - I'm using Scala, so I'm using a simple object MyObj extends App which takes no parameters at all.
I have tried adding <property name="dynamic.classpath" value="true" /> to the workspace.xml as suggested by other similar questions, but to no avail.
I used to be able to run my programs in my project fine before. But what lengthens a command line? What is being put on the command line at all?
This answer is based on IntelliJ 2020.1.4
Open the configuration. This is usually found in the Debug/Run toolbar.
You will find Shorten Command Line item in the Configuration dialog box. There are different modes that you can select there. In my case JAR Manifiest worked.
You can also set this as the default the next time you auto-generate a test.
Found the fix, this is SBT specific. I believe what is happening is that the libaryDependencies one puts in their build.sbt file actually adds all the jars of those dependencies to the classpath used to run your program.
To fix this, simply add
lazy val scriptClasspath = Seq("*")
(the lazy may be optional)
to your build.sbt file. I placed mine above the root val with the library dependencies. Not sure if that's necessary, but shift it around if you're having trouble
What this does, is upon running the program SBT will condense the "long" classpath built by those jars into a jar of its own, and just run that jar, which will kick off all of your dependencies and program.
Check this out for the longer demonstration, as well as other answers
Actually, we need to set Shorten command line: classpath file -
java WrapperClass classpathFile className [args]
You need to check carefully to see whether a lot of unrelated dependencies have been introduced.

Alternative to maven goal `eclipse:eclipse`

I was looking for information about mvn eclipse:eclipse and I realize that there are some obsolete goals here, one of them is eclipse:eclipse.
Is there any alternative to doing the same from the command line?
This plugin is deprecated, there's no need to use it anymore. In fact, it will do more harm than good.
In short: eclipse:eclipse generates all eclipse files based on the pom.xml. This means that if you change the pom, you always need the run the goal again. With m2eclipse it is aware of changes in the pom and will update your project on the fly in most cases. I know that if you update the source/target, you need to run a Maven Update from the context menu explicitly.

Send Maven output to console and log file using pom

Question: When running Maven in Eclipse, how do I send the console output to file?
I would like to achieve this using a pom setting or a maven plugin. I do not want to modify the run configurations or the maven system settings.
For reference, I am using Windows 7, Eclipse Luna, Java 6, Maven 3.
As per official command line options you could use -l,--log-file <arg> which provide the:
Log file where all build output will go.
As such, running:
mvn clean install -l output.log
Would not print anything to the console and automatically redirect the whole build output to the output.log file.
If you don't want to type it every time (or you actually don't want to use the command line) and you want it as default option (although rare case I would suppose), you could use new command line options behavior available since version 3.3.1 and have a .mvn folder where the concerned pom.xml file is located and a maven.config file in it simply providing the following line:
-l output.log
That is, the .mvn/maven.config file replaces MAVEN_OPTIONS just for its project, locally where it has been created, with the options it provides, not impacting other builds as per Maven settings of MAVEN_OPTIONS.
This is an IDE agnostic solution (it's a new built-in feature of Maven) and local to a project, but still not provided via simple POM editing, which cannot be achieved since the first phase of Maven default life cycle phases is validate, which:
validate the project is correct and all necessary information is available
That is, during the build, hence when the build has already started (and generated output), it validates the pom.xml file, hence too late to redirect build output at that stage based on some POM properties/plugin.
Go to run as and choose Run Configuration -> Commons -> Select a file.
This should redirect your output to the file you specified.
According to this you can try editing the ${MAVEN_HOME}/conf/logging/simplelogger.properties. I gave it a quick try and maven's output is redirected, but anything else writing to stdout (tests, for instance) still writes on the console
What about creating a fork of M2E and modifying it to read the output file for the launch config from pom.xml
https://github.com/eclipse/m2e-core.git
A possible solution is setting the output format in the mvn file. For example, in the directory /usr/bin, add the desired output informing the path the log will be saved at the end of exec "$JAVACMD" \ line: | tee /home/maven-log.log.
However, it only works when the maven is called by terminal line; when called by IDEs, like eclipse, this solutions does not work.

How to make -Dsbt.override.build.repos=true global for SBT?

I want to override all repos even the ones introduced inadvertently in my build.sbt files so we can point to our proxy and have a common binary base for all the team. The option
$ sbt -Dsbt.override.build.repos=true
does the job but I'd like to make this option permanent. I've been looking at http://www.scala-sbt.org/release/docs/Global-Settings.html but I don't know how to translate that option to the global.sbt file they mention.
How would you configure that option globally?
Add -Dsbt.override.build.repos=true to the SBT_OPTS environment variable
When running on windows, it can be defined in the file sbtconfig.txt under <SBT_HOME>/bin :
-Dsbt.override.build.repos=true
You can create this file if you don't have it already

How do I detect whether an Eclipse build failed?

Following on from this question, I now want to know how to stop an ANT script from executing if the preceding build failed. I can't see a way in the Build setup in Eclipse of chaining builds together based on their success.
I think I am lookikng for either a way to pass the previous build status into my ANT script so I can terminate or to never call the ANT script at all if the first build fails.
Any ideas?
No native way, AFAIK.
What you can do is modify your ant script to check if .class files produced by Eclipse are newer than WAR. If not, stop.
You should be able to store the success into a file. If you make sure the content of the file is a property file content the next ant task can use that file to fill in a property (like build.success) and can act on that.