Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the configuration and use of ivy

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about the configuration and use of ivy, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Maven is powerful, but there is something annoying about it. Seeing that Ivy seems to be becoming more and more mature, try to see how this little thing performs. After all, there is that powerful ant behind it.

one。 Download and install

Download from the official website http://ant.apache.org/ivy/ to the latest official version of ivy2.0.0 and choose the package of with dependencies.

Before installing ivy, install ant, because Ivy is based on ant; you need to choose the version of ant according to the version of ivy.

Download address: http://mirrors.tuna.tsinghua.edu.cn/apache//ant/ivy/2.4.0/apache-ivy-2.4.0-bin-with-deps.tar.gz

According to the installation on the official website, extract the downloaded ivy installation package, and then copy the jar file of ivy to the lib directory of ant (ANT_HOME/lib). Set the system properties IVY_HOME to the installation directory of ivy, such as D:\ ivy2.4.0.

two。 Set up the working directory

Ivy uses "ivy.default.ivy.user.dir" as the working directory, and ivy confirms the specific path to that directory in the following ways:

1. Find the variable ivy.default.ivy.user.dir

two。 If it is not found, look for the variable ivy.home

3. If you haven't found it yet, look for the variable user.home and use the user.home/.ivy directory

The first two variables do not exist until the default installation is not specifically set, so ivy uses user.home as the default working directory.

Ivy uses the cache directory to store cache files, and ivy confirms the specific path to that directory in the following ways:

1. Find the variable ivy.cache.dir

two。 If it is not found, the former ivy.cache.dir variable does not exist until ivy.default.ivy.user.dir/cache is installed by default and is not specifically set, so ivy uses ivy.default.ivy.user.dir/cache, and since ivy.default.ivy.user.dir uses user.home by default in this case, the end result is to use the user.home/cache directory.

To modify the default work path, it is obvious that you can set the values of several of the variables mentioned above. For example, if you need to set ivy.default.ivy.user.dir to a specific directory instead of using the user.home path of the current operating system, for ivy, you can set the ant property. For example, modify the build.xml file by adding the following

This modifies the work path and changes the cache directory to avoid dependence on the current operating system and users in cases such as reinstalling the operating system / installing multiple operating systems.

Because build.xml files are usually project files and need to be submitted to version control systems such as svn,git, it is not appropriate to write the path directly inside. Once modified, you need to change the build.xml of all projects, and different developers require the same path, which is not reasonable. Considering that ant can easily read system environment variables, you can define specific paths with environment variables, which ant simply uses:

Set the environment variable env.ivy.default.ivy.user.dir=D:\ ivy\ userdir

The reference in build.xml is as follows:

The above directory usage rules can be seen directly at the source code of ivy. It is clear that the constructor of IvySettings () in the class org.apache.ivy.core.settings.IvySettings can easily see the above rules.

three。 The configuration file path ivy uses the variable name ivy.settings.file to set the configuration file path, and since no relevant setting documentation is found, simply open the open source file to see the code.

In the class org.apache.ivy.ant.IvyAntSettings, the function defineDefaultSettingFile () has the relevant code:

1. Find the variable name ivy.settings.file

SettingsFileName = variableContainer.getVariable ("ivy.settings.file")

two。 The possible path, in turn, is the project BaseDir (which should be the BaseDir defined in the build.xml file of ant, usually the project root path). It is strange that the current path does not look for a path such as ivy.default.ivy.user.dir, or even ivy.settings.dir.

File [] settingsLocations = new File [] {

New File (getProject (). GetBaseDir (), settingsFileName)

New File (getProject () .getBaseDir (), "ivyconf.xml")

New File (settingsFileName)

New File ("ivyconf.xml")

}

3. Find the above four paths in turn

For (int I = 0; I < settingsLocations.length; iTunes +) {

File = settingsLocations [I]

Verbose ("searching settings file: trying" + file)

If (file.exists ()) {

Break

}

}

4. If it is not found, the default setting is taken.

If (! file.exists ()) {

Info ("no settings file found, using default...")

File = null

Url = IvySettings.getDefaultSettingsURL ()

}

The default configuration file is org.apache.ivy.core.settings.ivysettings.xml in the ivy.jar package, which is generally used if you do not make any related configuration.

Understand how ivy works, and it's easy to configure it. For example, if you want to set it separately for the current project, you can:

1. Place the ivyconf.xml file in the current project BaseDir directory

New File (getProject () .getBaseDir (), "ivyconf.xml")

This is the simplest solution, the strange thing is that the file name here is ivyconf.xml, very depressed, I tested with ivysettings.xml for a long time did not work, the original root knot in this place. The style is not uniform, which is probably due to the compatibility between the new and old versions. Fortunately, you can see the source code.

two。 Or set ivy.settings.file to the required file name at the same time, and place the file in the project BaseDir directory

New File (getProject (). GetBaseDir (), settingsFileName)

For example, set ivy.settings.file=ivysettings.xml, which is consistent with the file name in the jar package. It doesn't seem to be of much use?

3. In order for all projects to use the same configuration, consider pointing ivy.settings.file directly to a common configuration file

For example, set ivy.settings.file to ${env.ivy.default.ivy.user.dir} / ivysettings.xml

In this way, you don't have to set the same content repeatedly every time. For example, the public repository of ivy uses the official website repository of maven2 by default. We can modify it to use local private libraries of maven, such as nexus.

Settings in build.xml:

four。 Integrate with nexus

1. Ivysettings.xml

Put the original

Modify to

two。 Place the ivysettings-public.xml file in the same directory as ivysettings.xml

Actually copy the corresponding file from the ivy.jar package, and then modify it

Note that the name= "public" here cannot be changed, otherwise an error will be reported.

For information on the three repository of public, shared and private, please refer to the official documents, which are explained in detail.

Http://ant.apache.org/ivy/history/latest-release/tutorial/defaultconf.html

Summary:

1) install ant1.6+

Set env ANT_HOME=D:\ ant

Set Path, add ANT_HOME/bin

2) install ivy

Set env IVY_HOME=D:\ ivy\ ivy200

Set env ivy.default.ivy.user.dir=D:\ ivy\ userdir

3) config ivy for all projects and users

1. Copy ivysettings.xml to userdir

2. Copy ivysettings-public.xml to userdir

3. Open ivysettings-public.xml, edit m2 URL

4) add ivy setting to ant build.xml of project

Ivy.default.ivy.user.dir cannot be used as the name of an environment variable under linux! It had to be changed to IvyDefaultUserDir.

That is:

Set env IvyDefaultUserDir=D:\ ivy\ userdir

The above is how the configuration and use of ivy is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report