I am very new to maven. Our project is using maven and i am wanting to know if there is a way to force maven to build using source ONLY? Using no repo and not downloading anything. I have all the source required to build the whole project.
I just want to compile clean with out downloading or using the local repo.
Thanks
Usually not. The main reason is that you don't have all the sources.
Maven is a tool to manage dependencies for you. So you can say: "I need JUnit 4.11" and Maven will download it for you and make sure it's on the classpath when it's needed.
Now, if your project depends on JUnit 4.11, you can't compile it from source without the sources for JUnit. And Hamcrest. And probably a dozen other things.
So, no, you can't. Maven will compile the sources of your project but it won't try to locate the sources of all dependencies and compile them as well. Maven was built with the assumption that the binaries uploaded to Maven Central are correct and that the binaries were built from the attached source files (which are incomplete, btw, so you can't always build the project correctly from them).
Related
I have a workflow working on an application and one of its libraries that somewhat looks like this:
Make changes to library -> Push library jar to remote Maven repository with no version change -> Pull updated library jar from the remote repo to the downstream app -> Test and make changes to the app and library
But seems like the way IntelliJ indexes and/or caches Maven dependencies is not affected by me running a clean install from the Maven interface. Is there a surefire way to force IntelliJ to discard any cached dependency and reimport, or possibly do it only for a desired library?
Very likely this has nothing to do with IntelliJ. Since the version number is the same, maven won't re-download your dependency. Try to just delete the dependency locally from the maven repository:
rm -rf ~/.m2/repository/<..path to your library package..>
You could also avoid pushing the library to the remote repository, and test completely locally, by using the library as a local dependency. For this approach, see answers here: How to add local jar files to a Maven project?
Or since you are not effectively changes the library version the right approach would be to use the library project sources as a direct dependency for IDE maven project. For this - add this Maven library project as a new module to existing Maven project: File | New... | Module from Existing Sources... and select pom.xml file of this library project.
I am using Android with Maven in my project . It depends on zbar.jar which in turn depends on the secondary artifacts like .so files. I am able to install the zbar.jar in the maven repository , but my secondary artifacts like .so files are not getting pulling through the Maven repository.
Any advice is appreciated.
Maven is designed to handle Java code. The .so files are binaries compiled for a specific architecture.
Are you fully aware on the implications of using .so files?
You can
Either package the so file in a jar file and write custom code to
copy them in their correct position before your application runs
or locate a maven plugin that does what you want. (or even an
Android-Maven specific plugin)
See also Maven2 Dependencies and Native Libraries
I have a maven project that depends on several sbt project, which in turn depends on more projects. Are these transitive dependencies being resolved by maven? E.g. in packing of assemby jar?
Let me answer this question with mine: How can you know what build tool was used in a dependency?
You can't unless the build tool leaves some files to let you guess what the build tool could have been. But still, they're just files that are generated as part of the publishing process so the other build tools could resolve dependencies.
That's the point of any build tool to let you integrate with the other build systems in a less troublesome way.
Maven requires pom.xml and an appropriate repository layout. sbt follows the rules while publishing project artifacts to Maven repositories.
Ivy requires other files in repositories and sbt does generate them (by default).
Gradle plugs itself in to the game by following Maven's standard files and directory layout.
Read about publish task. You may want to consult the official documentation of sbt. Start with http://www.scala-sbt.org/0.13/docs/Publishing.html.
My Client wants to be able to build our project from source but does not want to connect to the internet to get any dependencies for the build. Note this will include plugin dependencies.
My proposal is that we provide the client with an archive containing all the dependencies in the correct Maven repo file structure, including checksums and meta information. They can then use this as an internal maven repo.
I have configured the maven-assembly-plugin to create such an archive, however it doesn't include all the build/plugin dependencies that their Maven will require to perform the build.
Does anyone know of a way to include build time dependencies in the archive, or can suggest another way to grab these dependencies and wrap them up in the correct structure.
Many thanks,
Pat
On a clean repository, you can run mvn dependency:go-offline. This will download all the plugins and dependencies relevant to the project. You can verify that this is good by doing an offline build (mvn -o clean install).
Once this works fine, you can create an archive of the repository and the sources and pass it on.
Have you taken a look into the maven-dependency-plugin and furthermore i would suggest to do a complete compile and package and after that you can package the local repository from that user ($HOME/.m2/repository). Than you have everything which is needed to do a full compile etc.
Try mvn dependency:copy-dependencies. This will copy all the dependencies to a directory target\dependency.
However, I'm not certain whether this includes the dependencies necessary to build, as well and those necessary to install the compiled output.
I have a Maven 2 multi-module project and want to be sure everything is taken from my local checked-out source.
Is it possible to tell Maven to never download anything for the modules it has the source of? Do I have to disable the remote repositories?
Does Maven always have to go the expensive way of installing a module into the local repository, and then extracting it again for each of its dependents?
Does Maven automatically first recompile dependencies for a module if their local source changed, and then compile the dependent?
Is it possible to tell Maven to never download anything for the modules it has the source of?
No. Maven 2 only "sees" the current module while it builds. On the plus side, you can build part of the tree by running Maven in a module.
Do I have to disable the remote repositories?
Yes, use the "offline" option -o or -offline. Or use settings.xml with a proxy that doesn't have any files. This isn't what you want, though.
Does Maven always have to go the expensive way of installing a module into the local repository, and then extracting it again for each of its dependents?
Yes but it's not expensive. During the build, the file is copied (that was expensive ten years ago). When a dependency is used, Maven just adds the path to the file to the Java process. So the file isn't copied or modified again. Maven assumes that files in the local repository don't change (or only change once when a download/install happens).
Does Maven automatically first recompile dependencies for a module if their local source changed?
No. There were plans for Maven 3 but I can't find an option to enable something like that.
To solve your issues, you should install a local proxy (like Nexus).
Maven download stuffs (dependencies) only if it's not available in your local reposiotory ($USER_HOME/.m2/repository). If you do not want anything to be downloaded use offline mode. This can be done by using -o switch. E.g.
mvn -o clean install
There is nothing expensive in it. If you are building the complete parent project, it will build all the modules and then copy the artifacts to your local repository. Then, when you build a project that has dependencies on those project, Maven will just copy them from local repository on your hard disk to the package that is going to be created for current project.
No. I have been burnt. Maven does not compile dependencies automatically. There is a plugin called Maven Reactor Plug-in. This plugin enables you to build a project's dependencies before the project is built.