-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] Add support for @(AndroidMavenLibrary). (…
…#8420) Context: #4528 Add support for the `@(AndroidMavenLibrary)` item group, which will download the requested Java artifact version from a Maven repository and add it as an `@(AndroidLibrary)` for binding. For example, to download the Maven package [pkg:maven/com.google.auto.value/[email protected]][0] from Maven Central and create an Android binding for it: <ItemGroup> <AndroidMavenLibrary Include="com.google.auto.value:auto-value-annotations" Version="1.10.4" /> </ItemGroup> ~~ Specification ~~ The `//AndroidMavenLibrary/@Include` format is `{GroupId}:{ArtifactId}`. Any additional attributes such as `%(Bind)` or `%(Pack)` will be copied to the created `@(AndroidLibrary)` item. `%(Bind)` and `%(Pack)` default to `true` and control the binding process as specified for [`@(AndroidLibrary)`][1]. `%(Repository)` controls which Maven Repository to download artifacts from. Supported values include: * `Central` for [Maven Central][2]. This is the default value if `%(Repository)` is not specified. * `Google` for [Google's Maven][3]. * A URL, for downloading from a custom Maven instance. *Note*: Maven authentication is *not* supported. ~~Examples:~~ <ItemGroup> <AndroidMavenLibrary Include="androidx.core:core" Version="1.9.0" Repository="Google" Bind="false" /> <AndroidMavenLibrary Include="com.github.chrisbanes:PhotoView" Version="2.3.0" Repository="https://repository.mulesoft.org/nexus/content/repositories/public" Pack="false" /> </ItemGroup> There are 2 parts to #4528: 1. Downloading artifacts from Maven 2. Ensuring all dependencies specified in the POM file are met Only (1) is currently addressed. (2) will be addressed in the future. [0]: https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations/1.10.4/ [1]: https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/OneDotNetEmbeddedResources.md#msbuild-item-groups [2]: https://repo1.maven.org/maven2/ [3]: https://maven.google.com/web/index.html
- Loading branch information
Showing
16 changed files
with
922 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# AndroidMavenLibrary | ||
|
||
Note: This feature is only available in .NET 9+. | ||
|
||
## Description | ||
|
||
`<AndroidMavenLibrary>` allows a Maven artifact to be specified which will automatically be downloaded and added to a .NET Android binding project. This can be useful to simplify maintenance of .NET Android bindings for artifacts hosted in Maven. | ||
|
||
## Specification | ||
|
||
A basic use of `<AndroidMavenLibrary>` looks like: | ||
|
||
```xml | ||
<!-- Include format is {GroupId}:{ArtifactId} --> | ||
<ItemGroup> | ||
<AndroidMavenLibrary Include="com.squareup.okhttp3:okhttp" Version="4.9.3" /> | ||
</ItemGroup> | ||
``` | ||
|
||
This will do two things at build time: | ||
- Download the Java [artifact](https://central.sonatype.com/artifact/com.squareup.okhttp3/okhttp/4.9.3) with group id `com.squareup.okhttp3`, artifact id `okhttp`, and version `4.9.3` from [Maven Central](https://central.sonatype.com/) to a local cache (if not already cached). | ||
- Add the cached package to the .NET Android bindings build as an [`<AndroidLibrary>`](https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/building-apps/build-items.md#androidlibrary). | ||
|
||
Note that only the requested Java artifact is added to the .NET Android bindings build. Any artifact dependencies are not added. If the requested artifact has dependencies, they must be fulfilled individually. | ||
|
||
### Options | ||
|
||
`<AndroidMavenLibrary>` defaults to using Maven Central, however it should support any Maven repository that does not require authentication. This can be controlled with the `Repository` attribute. | ||
|
||
Supported values are `Central` (default), `Google`, or a URL to another Maven repository. | ||
|
||
```xml | ||
<ItemGroup> | ||
<AndroidMavenLibrary | ||
Include="androidx.core:core" | ||
Version="1.9.0" | ||
Repository="Google" /> | ||
</ItemGroup> | ||
``` | ||
|
||
```xml | ||
<ItemGroup> | ||
<AndroidMavenLibrary | ||
Include="com.github.chrisbanes:PhotoView" | ||
Version="2.3.0" | ||
Repository="https://repository.mulesoft.org/nexus/content/repositories/public" /> | ||
</ItemGroup> | ||
``` | ||
|
||
Additionally, any attributes applied to the `<AndroidMavenLibrary>` element will be copied to the `<AndroidLibrary>` it creates internally. Thus, [attributes](https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/OneDotNetEmbeddedResources.md#msbuild-item-groups) like `Bind` and `Pack` can be used to control the binding process. (Both default to `true`.) | ||
|
||
```xml | ||
<ItemGroup> | ||
<AndroidMavenLibrary | ||
Include="androidx.core:core" | ||
Version="1.9.0" | ||
Repository="Google" | ||
Bind="false" | ||
Pack="false" /> | ||
</ItemGroup> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
build-tools/xaprepare/xaprepare/ThirdPartyNotices/MavenNet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace Xamarin.Android.Prepare | ||
{ | ||
[TPN] | ||
class MavenNet_TPN : ThirdPartyNotice | ||
{ | ||
static readonly Uri url = new Uri ("https://github.com/Redth/MavenNet/"); | ||
|
||
public override string LicenseFile => string.Empty; | ||
public override string Name => "Redth/MavenNet"; | ||
public override Uri SourceUrl => url; | ||
public override string LicenseText => @" | ||
MIT License | ||
Copyright (c) 2017 Jonathan Dick | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the ""Software""), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE."; | ||
|
||
public override bool Include (bool includeExternalDeps, bool includeBuildDeps) => includeExternalDeps; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...amarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.Maven.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Xamarin.Android.Bindings.Maven.targets | ||
This file contains MSBuild targets used to enable @(AndroidMavenLibrary) support. | ||
*********************************************************************************************** | ||
--> | ||
|
||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<UsingTask TaskName="Xamarin.Android.Tasks.MavenDownload" AssemblyFile="Xamarin.Android.Build.Tasks.dll" /> | ||
|
||
<PropertyGroup> | ||
<!-- Maven cache directory location --> | ||
<MavenCacheDirectory Condition="$([MSBuild]::IsOSPlatform('Windows')) and '$(MavenCacheDirectory)'==''">$(LocalAppData)\dotnet-android\MavenCacheDirectory\</MavenCacheDirectory> | ||
<MavenCacheDirectory Condition="$([MSBuild]::IsOSPlatform('OSX')) and '$(MavenCacheDirectory)'==''">$(HOME)/Library/Caches/dotnet-android/MavenCacheDirectory/</MavenCacheDirectory> | ||
<MavenCacheDirectory Condition="'$(MavenCacheDirectory)'==''">$(HOME)/.cache/dotnet-android/MavenCacheDirectory/</MavenCacheDirectory> | ||
<MavenCacheDirectory>$([MSBuild]::EnsureTrailingSlash('$(MavenCacheDirectory)'))</MavenCacheDirectory> | ||
</PropertyGroup> | ||
|
||
<Target Name="MavenRestore" | ||
Condition=" '@(AndroidMavenLibrary->Count())' != '0' " | ||
BeforeTargets="_CategorizeAndroidLibraries" | ||
DependsOnTargets="ResolvePackageAssets"> | ||
|
||
<!-- Download artifacts and POMs from Maven to a local cache. --> | ||
<MavenDownload MavenCacheDirectory="$(MavenCacheDirectory)" AndroidMavenLibraries="@(AndroidMavenLibrary)"> | ||
<Output TaskParameter="ResolvedAndroidMavenLibraries" ItemName="_ResolvedAndroidMavenLibraries" /> | ||
</MavenDownload> | ||
|
||
<!-- Add @(AndroidMavenLibrary)'s to @(AndroidLibrary)'s. --> | ||
<ItemGroup> | ||
<AndroidLibrary Include="@(_ResolvedAndroidMavenLibraries)" /> | ||
</ItemGroup> | ||
|
||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 59 additions & 1 deletion
60
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.