How to get maven 3.0 to only build modules with local scm changes - version-control

In maven 2.x you could use the reactor:make-scm-changes to build only modules with local scm changes.
Running this module with maven 3.0.3 results in a failure
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-reactor-plugin:1.0
:make-scm-changes (default-cli) on project my-project: The parameters 'artifactLis
t', 'folderList' for goal org.apache.maven.plugins:maven-reactor-plugin:1.0:make
-scm-changes are missing or invalid -> [Help 1]
This post seems to indicate there is no equivalent functionality for maven 3.0
http://mail-archives.apache.org/mod_mbox/maven-dev/201011.mbox/%3calpine.OSX.2.00.1011051125410.368#dfab-2.local%3e
Is there a replacement in maven 3.0 to get the functionality to only build modules that have local scm changes?

You could roll your own with a shell script that centers around:
svn --non-interactive status
Your shell script could do something like so:
PROJECT_LIST=`svn --non-interactive status | filter out target dir \
| cut out status \
| cut out subdirectories \
| replace line endings with ','`
mvn $* --projects=$PROJECT_LIST
I didn't test it out, but I know it's possible in theory.

Related

How to run pre build gradle java project in intellij

I have been using eclipse. Recently, I started using intellij IDE.
My project is core java project with gradle as build tool. In eclipse, i used to build the project through command like and import it into the project. Then i used to run it without any issues.
One of the below command i used to use frequently.
gradle -s --refresh dependencies clean build eclipse -x findbugsMain -x checkstyleMain
gradle -s --refresh dependencies clean build -x findbugsMain -x checkstyleMain
gradle build -x findbugsMain -x checkstyleMain
Now when i try imported my projects as module in intellij and try to run, it tries to build everything again and fails with error.
I do not want intellij to build the project again but to use the already build one which i did through command line.
If you build form command line first, then build from IDE with Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Build and run using option set to Gradle, IDE will reuse previous build cache results, provided that there were no changes since last Gradle build. It is important to note 2 things:
Build from IDE should be invoked as Build | Build action, not Rebuild. The Rebuild IDE action is not the same as Gradle clean build task. With clean build Gradle will re-use cache (if enabled) and will not rebuild all the classes and process all the resources if there were no changes. In case of the IDE Rebuild action - IDE will mark previous build results as "dirty" and will recompile all the classes and resources.
The Gradle you configure for the project in IDE settings must be the same as you use in command line. To be sure the same Gradle is used it is easier of all to configure to use Gradle wrapper for project.
Also if you do not want for the IDE to build at all you can remove Make action from Before launch section of your Run/Debug Configuration.

Why does sbt not choose the most recent dependency version within range?

in a build.sbt we can declare a range for a dependency; for example:
libraryDependencies += groupID %% "mylib" % "[2.0,)"
There are (in my case) multiple packages that fall within this range (I have 2.0.2, 2.0.3, 2.0.4 and even some more exotic versions like 2.0.1.dev and 2.0.3-dev of mylib available in my repository).
When I try to build this project, sbt consequently chooses version 2.0.2 for no apparent reason. I would expect him to take the biggest number within the range, but he never does. Here are the requirements I tried and the version he selected (so only when specifying an exact version number does he select a more recent version):
revision range | version selected
-----------------------------------------
[2.0,) | 2.0.2
[2.0.0,) | 2.0.2
]2.0,) | 2.0.2
2.0.+ | 2.0.2
latest.integration | 2.0.2
2.0.3 | 2.0.3
2.0.4 | 2.0.4
I have already tried the following workarounds:
removing the local ~/.sbt and ~/.ivy2 directories
running sbt -no-share -sbt-dir /tmp/sbt -ivy-dir /tmp/ivy to avoid any caching effect
searching my home directory for any file containing mylib in the name; only found ind ~/.ivy2
I have run most of my tests with sbt 0.13.16, but I have tried with 0.13.15 and 0.13.17
Note that all my builds run each time in a clean clone of my git repository; so no target directory remains.
the versions 2.0.2, 2.0.3 and 2.0.4 of mylib contain the same code and dependencies (I republished them for testing purposes)
The problem (for once) does not seem to reside in sbt.
I tried with sbt 1.2.1 and range 2.1.x. Now sbt complains that he cannot find this dependency; and he lists the available versions:
[warn] ==== my-maven-repo: tried
[warn] http://my-server/nexus/repository/my-repo/eu/company/mylib_2.12/[revision]/mylib_2.12-[revision].pom
[warn] [2.0.2, 2.0.2-dev.20180719.16.55.39.develop.dc3a706, 2.0.1-dev.20180719.16.49.57.develop.dc3a706, 2.0.1-dev.20180719.16.42.31.develop.dc3a706, 2.0.1.dev.20180719.16.31.59.develop.dc3a706]
so strangely he does not list all packages available on my nexus-maven repository.
After deleting one package using the nexus interface; it seems like this list was now complete.
So the real problem seems to be that sbt publish to a nexus repository does not recreate the index in that repository.
Workaround
I have created a custom sbt-publish-wrapper script to force nexus to recreate the repository metadata when publishing a new library:
#!/bin/bash
set -e
# just run sbt publish with the passed arguments as-is
sbt $# publish
# now make sure the repository on nexus is re-indexed
# this triggers a task to recreate metadata for all maven repositories. This task was manually configured in nexus.
# the id was obtained running `curl -v -u admin:***** -X GET http://my-company/nexus/service/rest/v1/tasks`
# the recreate-maven-repos needs only the nx-tasks-run privilege
curl -q -u recreate-maven-repos:recreate -X POST http://my-company/nexus/service/rest/v1/tasks/c42ab5f5-4bd6-4ed3-b2f1-d061c24a9b90/run

How I can list all sbt dependencies?

I need to list all sbt dependencies in order to check if already exists a debian package (I also notice that there is a DEB package but it seems that external dependencies are not packaged).
At the moment I did a list of sbt dependencies with the following steps:
Install sbt manually
I created a simple script that extract all jar files in ~/.ivi2 directory (excluding sbt jar). Here the result of the execution:
Group;Artifact;Artifact+Version
org.scala-lang;jline;jline-2.10.5
org.scala-lang;scala-compiler;scala-compiler-2.10.5
org.scala-lang;scala-library;scala-library-2.10.5
org.scala-lang;scala-reflect;scala-reflect-2.10.5
com.jcraft;jsch;jsch-0.1.46
org.scalamacros;quasiquotes_2.10;quasiquotes_2.10-2.0.1
jline;jline;jline-2.11
com.thoughtworks.paranamer;paranamer;paranamer-2.6
org.json4s;json4s-ast_2.10;json4s-ast_2.10-3.2.10
org.json4s;json4s-core_2.10;json4s-core_2.10-3.2.10
org.scala-lang.modules;scala-pickling_2.10;scala-pickling_2.10-0.10.0
org.scala-tools.sbinary;sbinary_2.10;sbinary_2.10-0.4.2
org.fusesource.jansi;jansi;jansi-1.4
org.spire-math;json4s-support_2.10;json4s-support_2.10-0.6.0
org.spire-math;jawn-parser_2.10;jawn-parser_2.10-0.6.0
Do you think is the right way to list all sbt dependencies?
There is a nice sbt plugin for that:
https://github.com/jrudolph/sbt-dependency-graph
Simply adding to ~/.sbt/0.13/plugins/plugins.sbt:
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.0")
Calling sbt dependencyTree you can get an "ascii graph" like:
...
[info] | +-org.apache.lucene:lucene-spatial:4.10.2
[info] | | +-com.spatial4j:spatial4j:0.4.1
[info] | | +-org.apache.lucene:lucene-core:4.10.2
[info] | | +-org.apache.lucene:lucene-queries:4.10.2
[info] | | +-org.apache.lucene:lucene-core:4.10.2
[info] | |
[info] | +-org.apache.lucene:lucene-suggest:4.10.2
[info] | +-org.apache.lucene:lucene-analyzers-common:4.10.2
[info] | | +-org.apache.lucene:lucene-core:4.10.2
[info] | |
[info] | +-org.apache.lucene:lucene-core:4.10.2
[info] | +-org.apache.lucene:lucene-misc:4.10.2
[info] | | +-org.apache.lucene:lucene-core:4.10.2
[info] | |
[info] | +-org.apache.lucene:lucene-queries:4.10.2
[info] | +-org.apache.lucene:lucene-core:4.10.2
...
In case the dependency hierarchy provided by sbt-dependency-graph is not needed, the following might be useful:
sbt 'show dependencyClasspathFiles'
Just adding here how to install sbt-dependency-graph, I think that is relevant for the question.
IMPORTANT:
The answer is just the part related to sbt-dependency-graph. The complete answer (sbt+scala+homebrew+plugin) you may find here
In order to use the Snyk CLI to test Scala projects, you will need to install the Sbt dependency graph plugin.
Installing the Sbt dependency graph plugin for sbt 0.13
Prerequisites
Ensure you have installed Scala.
Ensure you have installed Sbt and ran sbt.
NOTE: The steps below will install the Sbt dependency plugin as a global plugin.
First navigate to the correct directory by typing the following
command: cd ~/.sbt
This will take you to the Sbt directory. From there you will need to
navigate to the 0.13 directory. Typing the ls command will show if
0.13 and/or 1.0 exists in the directory
Navigate to 0.13 by typing: cd 0.13 and then make a directory called
plugins by typing: mkdir plugins
Navigate to the new directory by typing: cd plugins and then proceed
to create a file called “plugins.sbt” by typing: touch plugins.sbt
Edit the plugins.sbt file via your preferred editor
Add the following line to the file:
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1")
save the changes
Take the following steps for the 1.0 directory. Check if 1.0 exists
by typing ls in the sbt directory:
If the 1.0 does NOT exist in the sbt directory, type mkdir 1.0 in the sbt directory
If 1.0 exists in the directory, run the following command: cd ~/.sbt/1.0
Make a directory called “plugins” in that folder by typing: mkdir plugins
Copy the existing “plugins.sbt” file from the 0.13 directory to the current 1.0 directory by typing the following: cp ../0.13/plugins/plugins.sbt ./plugins
Validate that the plugin has been installed correctly by running the following command: sbt "-Dsbt.log.noformat=true" dependencyTree important This should be tested in the directory of the project and by running the command will generate the dependency graph. You can also run it each time you want to generate the dependency graph)

Configure repo for SBT launcher in Travis build

Where can I override the repo URL that SBT uses to fetch its launcher when the SBT instance is provided by Travis-CI?
http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.8/sbt-launch.jar is currently giving 404s and, as a result, the builds are failing on Travis with:
$ sbt clean dependencyUpdates coverage test coverageReport
Detected sbt version 0.13.8
Downloading sbt launcher for 0.13.8:
From http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.8/sbt-launch.jar
To /home/travis/.sbt/launchers/0.13.8/sbt-launch.jar
Download failed. Obtain the jar manually and place it at /home/travis/.sbt/launchers/0.13.8/sbt-launch.jar
I ran into the same problem today, and logged an issue for travis-ci: https://github.com/travis-ci/travis-ci/issues/4527
As a workaround, you can download the sbt-launcher.jar by adding a before_script section to your .travis.yml
before_script:
- mkdir -p $HOME/.sbt/launchers/0.13.8/
- curl -L -o $HOME/.sbt/launchers/0.13.8/sbt-launch.jar http://dl.bintray.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.8/sbt-launch.jar
We just deployed the fix to production. SBT builds should be working now.
Sorry for the inconvenience.
https://github.com/travis-ci/travis-ci/issues/4527#issuecomment-124123880

Command line argument is too long when using Maven's jaxws wsgen plugin because of long classpath

I'm trying to generate web service artifacts using the org.jvnet.jax-ws-commons jaxws-maven-plugin and the wsgen goal. It seems that part of the process is to execute a command that includes all the project jars on the classpath and this results in a command that exceeds character limit of the command line by more than double (on Windows 7). How can I workaround this?
[INFO] --- jaxws-maven-plugin:2.3:wsgen (generate-wsdl) # interface ---
[INFO] Processing: com.mycompany.myproject.MyWebService
[INFO] jaxws:wsgen args: [-keep, -s, D:\Dev\myproject\target\generated-sources\wsgen, -d, D:\Dev\myproject\target\classes, -encoding, Cp1252, com.mycompany.myproject.MyWebService]
[WARNING] Length of the command is limitted to 8191 characters but it has 15450 characters.
[WARNING] cmd.exe /X /C "D:\java\jdk1.6.0_26\jre\bin\java.exe
-Xbootclasspath/p:
D:\m2repo\javax\annotation\javax.annotation-api\1.2-b03\javax.annotation-api-1.2-b03.jar;
D:\m2repo\javax\jws\jsr181-api\1.0-MR1\jsr181-api-1.0-MR1.jar;
D:\m2repo\javax\xml\ws\jaxws-api\2.2.9\jaxws-api-2.2.9.jar;
D:\m2repo\javax\xml\soap\saaj-api\1.3.4\saaj-api-1.3.4.jar;
D:\m2repo\javax\xml\bind\jaxb-api\2.2.7\jaxb-api-2.2.7.jar
-cp
/D:/m2repo/org/jvnet/jax-ws-commons/jaxws-maven-plugin/2.3/jaxws-maven-plugin-2.3.jar org.jvnet.jax_ws_commons.jaxws.Invoker com.sun.tools.ws.wscompile.WsgenTool
-pathfile
C:\Users\me\AppData\Local\Temp\jax-ws-mvn-plugin-cp83681795198066117.txt
-cp
<long list of project jars from .m2 repository>
-keep
-s D:\Dev\project\target\generated-sources\wsgen
-d D:\Dev\project\target\classes
-encoding Cp1252
com.mycompany.myproject.MyWebService"
The command line is too long.
This is a known bug (JAX-WS-COMMON-110) that will be fixed in version 2.3.1.
Until jaxws-maven-plugin 2.3.1 is officially released, you may compile it from svn.
svn checkout https://svn.java.net/svn/jax-ws-commons~svn/tags/jaxws-maven-plugin-2.3.1-b03
cd jaxws-maven-plugin-2.3.1-b03
mvn install
And then update your pom.xml to use the 2.3.1-b03 version:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3.1-b03</version>
...
</plugin>
You don't need to build the updated version yourself, it can be downloaded from the Maven repository
http://search.maven.org/#artifactdetails|org.jvnet.jax-ws-commons|jaxws-maven-plugin|2.3.1-b03|maven-plugin