I'm a professional services consultant for a software product company. Our product provides a Java API so field customizations can be built. These extensions are dependent upon up to 50 individual JAR files - some proprietary to our product, others are open source.
I don't want to hard code the dependencies in the POM for several reasons - mostly because each new release will depend on slighty different versions of the open source artifacts. When a new product is released, I simply want to point to the new installation folder and rebuild the extensions.
So, I'm trying to create a Maven plugin that takes a reference to the installation folder, recurses through the folders, and automatically adds all *.jar files to the compile-time classpath.
I tried this:
Map<?, ?> context = getPluginContext();
MavenProject maven = (MavenProject) context.get("project");
List<String> classpath = maven.getCompileClasspathElements();
// start adding additional elements to the classpath
That snippet executes during the initialize phase, but the classpath reverts by the time compiling starts and the compile fails. Am I even going about this the right way?
This doesn't sound like the way to go.
Rather try to analyze how the installation folder is assembled. Try to create this installation folder with Maven, too, and provide a POM with all used dependencies (BOM - Bill of Materials).
Then use this BOM-POM as dependency (scope=provided) in your extensions.
Related
I am a beginner with gradle and i need help please.
If i want my own libs and extern libs (vendor) where shoud i put these libs (extern and personnal)?
thank you for helping !
(example: a screenshot of my current dir structure)
Gradle gives you a few different options for this.
In all cases, there is no fixed folder structure for local file dependencies, and you are free to chose what you like. libs seems fine to me.
All examples below are in Groovy DSL. Refer to the Gradle user guide for the Kotlin DSL variants.
File dependencies
To add dependencies from a local folder, you can use the Project.file() or Project.fileTree() methods. Both take a path that is resolved relative to the project directory.
dependencies {
implementation files('libs/a.jar') // Single file
implementation files('libs/b.jar', 'libs/c.jar') // Multiple files
implementation fileTree('libs') // All files in a folder
implementation fileTree('libs') { include '*.jar' } // All jar files in a folder
}
See File dependencies in the user guide for more information.
Flat directory repository
You can also declare a flat directory repository. Here the path is relative to where you invoke Gradle from, so to make it consistent, you should make it absolute (using projectDir or rootDir).
repositories {
flatDir name: 'local-libs', dirs: "$projectDir/libs" // The name is optional
}
You can then declare dependencies using the normal format with a group, name and version. However, as group is ignored so you can either write whatever you like, or just leave it out:
dependencies {
implementation 'mysql:mysql-connector-java:5.1.49' // Real Maven coordinates
implementation ':mysql-connector-java:5.1.49' // Short-hand for local coordinates
}
See this section for more information.
Maven repositories and separate Gradle projects
Because the above two methods do not include module metadata, meaning you have to define and include all transitive dependencies manually, it can quickly get hairy to maintain.
If possible, try and use Maven repositories. Especially for third-party dependencies. You can even define a local repository to take advantage of metadata files (e.g. .pom files or .module) if you can't use remote ones like Maven Central or JCenter.
When depending on other Gradle projects, if they are related, you could possibly structure them as a multi-projects instead of building and putting them into a "libs" folder.
If they are not related, you could also publish them to a Maven repository (either local or remote), or you could look into composite builds, though this is a bit of an advanced topic.
A note on the MySQL Connector software license
Lastly, in case you are not aware, the community edition of MySQL Connector/J version 5.x is licensed under GPL v2. It means your own application also needs to be licensed under GPL v2.
Later versions like 8.x (I am unsure about 6 and 7) are licensed dually under GPL v2, but has a provision called The Universal FOSS Exception that allows you to link and use the library in your own application without affecting your own license.
If this is just a hobby project, no one will come knowing on your door if you breach the license. But if it is for a company, be careful or you might bring it into legal trouble. Oracle does audits from time to time and they are not known to let an opportunity slide for slapping you in the face with a big license fee.
Noob question. I'm considering to learn Maven. I understand what it does in general. Let's say I have a Maven Eclipse project. Then I create an executable JAR, and wrap it with launch4j.
Now I have TestProgram.exe file. Will Maven reload the dependencies, whenever there is a there is a new version available? Will the inner structure of the TestProgram.exe change over time as new versions of dependencies are loaded? Or does Maven update dependencies only during the development stage?
Maven is a build tool. One of it's key benefits is that it yields a repeatable build process. It does not become part of your application.
The artefacts that are included in your build are fixed by the dependency versions that you specify in your project object model (aka pom.xml file).
If you need a newer version of one of these dependencies then you must update your pom.xml file and release a new version of your product.
I am in the processing of integrating Maven into my my projects. While maven has plenty of pros i'm finding it difficult to figure out how to maintain my current development process, which is as follows:
For creating SDKs I will create a sample app, which will depend on and directly reference the SDK source code, all from within the same code project. This means that I can make easily change/debug the SDK code with one click run/debugging.
I fear this won't really be possible with Maven. Can I create some type of Hybrid approach, where I continue my normal development approach and then push builds to Maven when it is appropriate.
Update - For Clarity
My problem is that when everything is done through maven, the dependencies are built and published to Maven. Then, the dependent project pulls down compiled references and uses them. My issues is that I don't want to go through this whole process every time I make a small change to a dependency.Thanks.
You should try creating parent level pom.xml with two modules - your library and simple app to test it. In simple app's pom.xml provide a dependency on library module.
Then open in your IDE parent pom as maven project. This should be sufficient for normal debug.
Other possible approach - install you library artifact into maven repo with sources. In this case you will be able to debug it, but test app still have to load use jars from repo.
Why there's a difference in Default Source Lookup Path between GWT and java launch configurations?
In multi-module projects instead of containing projects, the Default folder contains the class folders of those projects!
It causes "Source not found" errors when the debugger steps into a dependency project.
I know I can add projects manually. Just want to know why this difference is needed.
The only project in the list is the associated with the .launch.
GWT needs '.java' source files of dependencies to be able to compile (translate to js) while the Java launcher needs only '.class' compiled files.
I suppose you know GWT has a different way to manage dependencies (through modules within the same project), which is good for some advanced GWT practices like loading a module's js lazily (this feature doesn't work with "foreign" libs/projects).
So this could also be an answer for why eclipse GWT doesn't suppose you will have more projects (but more modules instead)
Finally if you really have an independent GWT lib that you're maintaining this is an issue as you said.
I've a multimodule project that is mostly open source but has one module (a compiler) that is proprietary so its src/main/java folder needs to be removed before releasing. The proprietary modules builds an obfuscated jar which is used by other modules that need to invoke the compiler from the original jar to build everything else in the release. One of these is a mojo that is used to compile the rest of the system. So after removing proprietary sources, I need to wind up with a working mojo so users can compile the non-proprietary parts of the system using binary-only obfuscated compiler jars.
Call the proprietary module "compiler" and the obfuscated jar it produces "compiler.jar". I think I need another module, "compiler-bin", with "compiler.jar" as a dependency, that adds compiler.jar to the repository with the new name, "compiler-bin.jar", then change everything (mojo, etc) to depend on compiler-bin.jar instead of compiler.jar. Then distribute by cloning the whole tree, remove the compiler source module by hand, hand-tweak the poms to repair the breakage, and...; it gets to be a fair bit of work.
I'm hoping for something more automatic that derives a new copy of the original tree (with all sources) to produce a for-distribution tree (minus proprietary sources) that can be built without further hand-tweaking.
If you want special packaging for your artifacts, then you will have to create your own assembly, by using maven-assembly-plugin.
Look here for an example -> https://stackoverflow.com/a/7838060/185722
Found the maven assembly plugin hopelessly complicated, then found a better way.
I simply create a svn branch based on the trunk we're releasing, then delete the unwanted folders in the branch, keeping them in the trunk. Then test, tweak anything that needs tweaking (delete children links in parent poms for example). Then assign the branch a maven release number (avoiding the maven release plugin as too fragile and complicated) with mvn versions:set -DnewVersion=whatever. Commit the branch, upload the build results and you're done.