将内部Ivy仓库替换为Artifactory并迁移至Maven的技术咨询
Hey there, let’s break this down step by step since you’re new to both Ivy and Maven—no need to feel stuck! The makepom Ant task is great for basic conversions, but it’s definitely limited when it comes to handling Ivy’s more flexible configurations and publications nodes. Here’s how to map those to Maven’s structure manually:
First: Understand Ivy Configurations ↔ Maven Equivalents
Ivy’s configurations are all about grouping dependencies and defining which artifacts get used where. Maven uses dependency scopes and (for advanced cases) profiles to handle this. Here’s the most common mapping:
- Ivy’s
compileconfiguration → Maven’scompilescope (default, used for main code) - Ivy’s
testconfiguration → Maven’stestscope (only for test code) - Ivy’s
providedconfiguration → Maven’sprovidedscope (like servlet APIs, provided by the runtime) - Ivy’s
runtimeconfiguration → Maven’sruntimescope (used at runtime but not compilation)
If you have custom configurations (e.g., dev for development-only dependencies), you’ll need to either map them to an existing Maven scope or use Maven profiles to activate those dependencies only in specific environments.
How to Fix Dependencies After makepom
When makepom generates your pom.xml, it probably dumped all dependencies into the default compile scope. Go through your original ivy.xml and adjust each dependency’s <scope> in the pom to match its Ivy configuration. For example:
<!-- Ivy dependency in test configuration --> <dependency org="junit" name="junit" rev="4.13.2" conf="test->default"/> <!-- Becomes this in pom.xml --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency>
Next: Translate Ivy Publications to Maven Build Plugins
Ivy’s publications define which artifacts you want to publish (e.g., main JAR, sources JAR, javadoc). Maven handles this via its default packaging (usually JAR) plus plugins to attach additional artifacts.
Common Publication Mappings
- Main JAR: Maven automatically builds this if your
packagingis set tojar(whichmakepomshould have done). - Sources/Javadoc JARs: If your Ivy publications include these, add the following plugins to your pom’s
<build><plugins>section:<!-- Attach sources JAR --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.2.1</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <!-- Attach javadoc JAR --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>3.5.0</version> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> - Custom Artifacts (e.g., shaded JARs, zip distributions): Use plugins like
maven-assembly-pluginormaven-shade-pluginto define and publish these, matching what your Ivy publications did.
Step-by-Step Migration Workflow
- Generate Base Pom: Use
makepomto get the basic structure (groupId, artifactId, version, core dependencies). - Fix Dependency Scopes: Manually update each dependency’s scope to match its original Ivy configuration.
- Add Publication Plugins: Configure Maven plugins to replicate your Ivy publications.
- Test Locally: Run
mvn clean installto build and install artifacts to your local Maven repo—verify everything compiles and dependencies are resolved correctly. - Configure Artifactory: Update your
settings.xmlto point to your Artifactory instance (add release and snapshot repositories). Then runmvn deployto push artifacts to Artifactory.
Quick Tips for Newbies
- Start with a small, simple project first—get that working before tackling larger, more complex ones.
- Don’t overcomplicate custom configurations right away—stick to standard Maven scopes unless you really need the flexibility.
- If you’re unsure about a plugin or scope, you can look up Maven’s official docs as you go; no need to memorize everything upfront.
内容的提问来源于stack exchange,提问作者Ed Dunn

